Well, to build my menu my menu I use a db similar structure like this
2 Services 0
3 Photo Gallery 0
4 Home
i would use a recursive function.
i know this isn't exactly like your code, but I think you can get the general concept if you understand recursion. if you don't understand recursion check out http://en.wikipedia.org/wiki/Recursion_(computer_science)
$list = new List();
function print_menu($list) {
echo '';
foreach($list as $item) {
echo '- ' . $item->name . '';
if($item->has_child) {
print_menu($item);
}
echo '
';
}
echo '
';
}