I now have this code:

<? if ($menu): ?> <ul class="nav"> <li><a href="http://<?=$_SERVER['SERVER_NAME'];?>"> SITE</a></li> <?foreach($menu as $item): if($item['parent'] == 0):?> <li><a class="parentItem" href="/p/<?=$item['url'];?>"> <?=$item['name'];?></a> </li> <? endif; endforeach; ?> </ul> <ul class="nav right"> <li><a><i class="icon-profile"></i> <?=$user['first_name']." ".$user['last_name'];?></a></li> <? if($user['level'] == 1):?> <li><a href="/admin">Администрирование</a></li> <? endif;?> <li><a href="/logout"><i class="icon-signout"></i> Выход</a></li> </ul> <? endif; ?> 

Condition: there is 1 array where all menu items are located, both main and under the menu. To determine there is a special cell - parent. Actually, I got all the items where there is no parent (parent = 0), it remains for them to get under the menu.
How to do it?
Is it possible to format an array somehow? I tried to do it through the function, but it turned out badly, because arrays are not cleaned and gives the same value everywhere.

    1 answer 1

    In google, on a request like " Building a hierarchy tree " - information is a sea, so I see no reason to repeat here. And it would be better if you did not show your code, for which you can pick up the minuses, that the dog is a flea, but showed the same array. In general, recursion to help you.