I have an array in which I keep a menu of more than 100 elements and then print it as a CSS drop-down menu. There are 5 main menus and these have sub-menus, and some of these have sub-menus etc etc. Right now I'm hard coding the loops when printing them, but I'm sure there must be some clever way of doing it in only a few lines of code! This is what the beginning of the array looks like:
$menu = array(
array(
'title' => 'Travel tips',
'url' => 'travel-tips',
'sub' => array(
array(
'title' => 'Travel guide',
'url' => 'travel-guide'),
array(
'title' => 'Places to visit',
'url' => 'places-to-visit',
'sub' => array(
array(
'title' => 'Ahu Akivi',
'url' => 'ahu-akivi'),
array(
'title' => 'Ahu Tongariki',
'url' => 'ahu-tongariki'),
array(
'title' => 'Anakena',
'url' => 'anakena'),
array(
'title' => 'Orongo',
'url' => 'orongo'),
array(
'title' => 'Rano Kau',
'url' => 'rano-kau'),
array(
'title' => 'Rano Raraku',
'url' => 'rano-raraku'),
array(
'title' => 'Vinapu',
'url' => 'vinapu'))),
array(
'title' => 'Things to do',
'url' => 'things-to-do',
'sub' => array(
array(
'title' => 'Beaches',
'url' => 'beaches'),
array(
'title' => 'Church',
'url' => 'church'),
array(
'title' => 'Fishing',
'url' => 'fishing'),
...and then it goes on and on. How can I loop this neatly and cleanly in only a few lines of code recursively without hard-coding the loops?
override