<?php function printMenu(&$children) { // HTML here for the sake of example. Normally I would avoid // this. :) echo '<ul>'; foreach ($children as $id => $child) { echo '<li>'; if ($child['URL'] != null) { printf('<a href="%s" id="%s">%s</a>',$child['URL'], htmlentities($id),htmlentities($child['name'])); } else { printf('%s',htmlentities($child['name'])); } echo "\n"; // so we have some nice HTML :)
// here's the recursion. if (count($child['children'])) printMenu($child['children']);
Whoops. It should probably
Whoops. It should probably look like this:
<?php
function printMenu(&$children)
{
// HTML here for the sake of example. Normally I would avoid
// this. :)
echo '<ul>';
foreach ($children as $id => $child)
{
echo '<li>';
if ($child['URL'] != null) {
printf('<a href="%s" id="%s">%s</a>',$child['URL'],
htmlentities($id),htmlentities($child['name']));
} else {
printf('%s',htmlentities($child['name']));
}
echo "\n"; // so we have some nice HTML :)
// here's the recursion.
if (count($child['children']))
printMenu($child['children']);
echo '</li>';
}
echo "</ul>\n";
}
?>