I've $menu_array3
as
Array
(
[9] => Array
(
[category_name] => cat1
[category_id] => 9
[children] => Array
(
[12] => Array
(
[category_name] => test5
[category_id] => 12
)
[10] => Array
(
[category_name] => cat2
[category_id] => 10
[children] => Array
(
[15] => Array
(
[category_name] => cat7
[category_id] => 15
[children] => Array
(
[18] => Array
(
[category_name] => cat10
[category_id] => 18
)
[16] => Array
(
[category_name] => cat8
[category_id] => 16
)
)
)
[17] => Array
(
[category_name] => cat9
[category_id] => 17
)
)
)
)
)
[11] => Array
(
[category_name] => cat3
[category_id] => 11
[children] => Array
(
[13] => Array
(
[category_name] => cat5
[category_id] => 13
)
)
)
)
with ref to this answer I tried to build navigation menu using
function build_nav($category_name, $data)
{
$result = array();
foreach ($data as $row)
{
if ($row['category_name'] == $category_name)
{
$result = "<li>" . $row['category_name'] . "</li>";
$result= build_nav($row['category_name'], $data);
}
}
return $result;
}
$menu="<ul>";
$menu.=build_nav('cat1', $menu_array3);
$menu.="</ul>";
echo "menu <pre>"; print_r($menu); echo "</pre>";
But i was stopped by
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 261900 bytes)
I request you to correct me with suggestions. Thanks in advance Edit I found solution to build navigation menu directly from db at https://stackoverflow.com/a/3380296/1528701