I have a code like this.
<ul>
<?php foreach (getUserMainMenus($get_user_id) as $get_main_menu): ?>
<li class='has-sub'><a href='#'><span><?=$get_main_menu['menu_name']; ?></span></a>
<ul>
<?php foreach (getUserChildMenu($get_main_menu['m_id'], $get_user_id) as $sub_menu): ?>
<li class='has-sub'><a href='<?=$sub_menu['menu_url']; ?>'><span><?=$sub_menu['menu_name']; ?></span></a>
<ul>
<?php foreach (getUserSubChildMenu($sub_menu['m_id'], $get_user_id) as $sub_sub_menu): ?>
<li class='has-sub'><a href='<?=$sub_sub_menu['menu_url']; ?>'><span><?=$sub_sub_menu['menu_name']; ?></span></a></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
And the result set for the second foreach is like this.
Array ( [m_id] => 9 [menu_name] => MenuName [parent_menu_id] => 4 [menu_order] => 1 [menu_url] => menu1.php [status] => 1 )
How to check a if condition after all foreach statement. In other words, i need to get the $sub_menu values and if there is values show the li tag. Also - I need to check the $sub_sub_menu variable, and if there is values show the li tag.
How can i achieve that?
Thanks, Kimz
I guess you try to create a navigation menu. Where the sub entries should only appear when the top menu item is selected by the visitor of your page.
Is that right?
Ok if so. You might have in mind that.
What your job here is, you have to make sure that your script detects which top-menu item is clicked at.
Do you need more help, or is it clear what to do?
Ok how about this as an basic example for dynamic php menus as test.php
See any top menu item hands over the additional variable "menu". This is either "top1" or "top2" in this case. Now your script on reload checks whether "menu" is already set and depending on the value of "menu" it shows the corresponding sub menu.
There is still a long way to go, because in my case I use fixed menu items where in your case you load the menu items depending on the "userid".
Let me know if the example above works at your place and if you need additional support to adopt it to your dynamically loaded menus.
Following that idea you need to replace
by adding for example the variable name "level0"
then you can check in you sub menu if "level0" is set as you expect it and then show or hide the sub menu items.