I did research on this, and wasn't able to find an exact answer. Most of the questions/answers on here pertaining to this seem to be unfinished. If anyone knows of a finished solution similar to my question, please point me in that direction!
Here is my array:
Array
(
['home'] => Array
(
[0] => sub-home1
[1] => sub-home2
)
['about'] => Array
(
[0] => sub-about
['about2'] => Array
(
[0] => sub-sub-about
)
)
['staff'] => Array
(
[0] => sub-staff1
[1] => sub-staff2
)
['contact'] => contact
)
And here is what I would like to turn it into:
<ul>
<li><a href="">home<a/>
<ul>
<li><a href="">sub-home1</a></li>
<li><a href="">sub-home2</a></li>
</ul>
</li>
<li><a href="">about<a/>
<ul>
<li><a href="">sub-about</a></li>
<li><a href="">about2</a>
<ul>
<li><a href="">sub-sub-about<a/></li>
</ul>
</li>
</ul>
</li>
<li><a href="">staff<a/>
<ul>
<li><a href="">sub-staff1</a></li>
<li><a href="">sub-staff2</a></li>
</ul>
</li>
<li><a href="">contact<a/></li>
</ul>
The array will be dynamically generated, but will have a limit of 3 levels ex: about->about2->sub-sub-about. I tried going off of this question: PHP/MySQL Navigation Menu but they didn't really seem to come to a conclusion? I am familiar with foreach's whiles and for loops but I just can't seem to wrap my head around this one.
EDIT: Enzino, your code works!
I think you can use recursion? Here is some pseudocode, not very familiar with php.
Here is my solution:
Calvin's solution worked for me. Here's the edited version. We can use more nested loops to get sub - sub menu items.
I would probably slightly adapt the array to be something like the following:
With a structure like this you could use recursion to build your menu HTML: