Multidimensional array for nested menu items

This sort of parent/child thing can be handled in one of two ways:1. Recursively. You write a function that displays the menu for a particular parent (or 0). It calls itself recursively on each child in case it has its own children.2. Linearly with a stack. It's basically recursive but instead of function calls you track everything in an array.

#1 is definitely easier.

Can you write that function? Take a look at the code in the other thread for an example. It should look something like

function whateverYouWantToCallThisThing($link, $parent) {
run a query for the children of $parent
if there are children {
output a <ul>
for each child in the result {
output the opening <li> and link
whateverYouWantTocallThisThing($link, child)
output the closing </li>
}
output a </ul>
}
}

I am having problems getting a multi level menu working and have read a lot of previous forum posts trying to make sense of it and an example like https://forums.phpfr...ay#entry1544308 should probably tell me everything I need to know, but I simply cannot get my head around this correctly and make it work. I hope there are some experienced coders here who will bare with my n00bness hehe..

This sort of parent/child thing can be handled in one of two ways:1. Recursively. You write a function that displays the menu for a particular parent (or 0). It calls itself recursively on each child in case it has its own children.2. Linearly with a stack. It's basically recursive but instead of function calls you track everything in an array.

#1 is definitely easier.

Can you write that function? Take a look at the code in the other thread for an example. It should look something like

function whateverYouWantToCallThisThing($link, $parent) {
run a query for the children of $parent
if there are children {
output a <ul>
for each child in the result {
output the opening <li> and link
whateverYouWantTocallThisThing($link, child)
output the closing </li>
}
output a </ul>
}
}