Thanks guys. I was wrong about my way. Please don’t post anymore.
I had some trouble with my array.
I generate my array in this way:
private function _getMenuBar(){
$data = array();
$query = $this->db->query("SELECT * FROM df_menubar_table WHERE visible = 1 AND parent = -1 ORDER BY priority");
foreach($query->result_array() as $row){
$data[count($data)] = array(
"menu" => array(
"title" => $row['title'],
"url" => $row['url'],
"name" => $row['name'],
"selected" => 0
)
);
}
return $data;
}
As usual array will feed like
array[0] = menu => array(title,url,name,selected);
but I want to not define $data[**count($data)**] as index and define ‘menu’ as index. And CodeIgniter doesn’t support something like this for passing to views. Therefore I need to key be the menu.
It means:
array[0] = menu => array(title,url,name,selected);
To:
array[‘menu’] = array(title,url,name,selected);
BTW, I tried += but It just stored the last row.
Thanks.
Edit:
I tried your way it turned to this:
I tried it. But it turned to this:
array(1) {
["menu"]=>
array(5) {
[0]=>
array(1) {
["menu"]=>
array(4) {
["title"]=>
string(8) "اصلی"
["url"]=>
string(30) "http://localhost/dreamfactory/"
["name"]=>
NULL
["selected"]=>
int(0)
}
}
You need some type of unique identifier. Adding multiple items to array[‘menu’], with no unique identifier, will cause the last/newest item to overwrite the ones before. You can have an array set up like below.
The last one can be with or with out the menu item.
Code will look like below (simplified)