I have an array which contains the data to build a nav menu on the site.
This is how it's setup:
$menu = array();
$menu['0']['label'] = 'Home';
$menu['0']['icon'] = 'fa-home';
$menu['0']['id'] = '';
$menu['0']['class'] = '';
$menu['0']['url'] = '/index.php';
$menu['0']['blank'] = 0;
$menu['1']['label'] = 'Admin';
$menu['1']['icon'] = 'fa-user';
$menu['1']['id'] = '';
$menu['1']['class'] = '';
$menu['1']['url'] = '#';
$menu['1']['blank'] = 0;
$menu['1']['0']['label'] = 'Notes';
$menu['1']['0']['icon'] = '';
$menu['1']['0']['id'] = '';
$menu['1']['0']['class'] = '';
$menu['1']['0']['url'] = '/notes.php';
$menu['1']['0']['blank'] = 0;
$menu['1']['1']['label'] = 'Testing';
$menu['1']['1']['icon'] = '';
$menu['1']['1']['id'] = '';
$menu['1']['1']['class'] = '';
$menu['1']['1']['url'] = '/testing.php';
$menu['1']['1']['blank'] = 0;
$menu['2']['label'] = 'Resources';
$menu['2']['icon'] = 'fa-thumb-tack';
$menu['2']['id'] = '';
$menu['2']['class'] = '';
$menu['2']['url'] = '#';
$menu['2']['blank'] = 0;
Where $menu['0']
, $menu['1']
, etc. are all shown on the main nav menu. Any array underneath them, such as $menu['1']['0']
are all submenus under their parent.
I am trying to check each main element on the array to see if there is a sub-array (if there are any submenus to create).
foreach ($menu as $item) {
if (is_array($item)) {
foreach ($item as $subitem) {
print_r($subitem); // See notes below
}
}
}
What I am trying to do with print_r($subitem)
is come up with an array like:
$subitem['label'] = 'Notes';
$subitem['icon'] = '';
$subitem['id'] = '';
$subitem['class'] = '';
$subitem['url'] = '/notes.php';
$subitem['blank'] = 0;
Ideas?