I am attemptting to attach a small CMS to a website I am creating. However I have come across a small problem. The CMS uses PHP functions for inserting menus, these PHP func
I think this outputs the correct HTML structure.
function GenerateMenu($arr)
{
foreach($arr as $val) {
if (next($arr)) { $nextitem = current($arr); }
if (is_array($val)) {
$output .= "\n\n" . GenerateMenu($val, $output) . "
\n\n\n";
}
elseif (is_array($nextitem)) { $output .= "- " . $val; }
else { $output .= "
- " . $val . "
\n"; }
}
return $output;
}
$html = GenerateMenu($menu);
echo("\n" . $html . '
');
Same test code as above:
$menu = array('Projects (Menu Level 1)',
array('Project 1 (Menu Level 2)',
'Project 2 (Menu Level 2)',
'Project 3 (Menu Level 2)'),
'News (Menu Level 1)',
'Contact (Menu Level 1)');