I have a PHP array with menu items and submenu items. The submenu items are set with a parent ID and depth. An example array looks like this:
[0] => stdClass Object ( [CategoryID] => 4 [ParentCategoryID] => -1 [Depth] => 1 [Name] => Menu1
[1] => stdClass Object ( [CategoryID] => 2 [ParentCategoryID] => 4 [Depth] => 2 [Name] => Submenu1
[2] => stdClass Object ( [CategoryID] => 3 [ParentCategoryID] => 4 [Depth] => 2 [Name] => Submenu2
[3] => stdClass Object ( [CategoryID] => 1 [ParentCategoryID] => -1 [Depth] => 1 [Name] => Menu2
Now I want to have the array output as a list and sublist like this:
<ul>
<li>
Menu1
<ul>
<li>Submenu1</li>
<li>Submenu2</li>
<ul>
</li>
<li>
Menu2
</li>
<ul>
I was not able to get those submenus to the parent element. Is there any way to do this in an easy way?