I'm trying to create a multidimensional array which stores a website navigation. Currently my navigation consists of Main -> Level 1 -> Level 2. I am having issues accessing level 2 correctly.
My Array example array is...
$pages = array
(
array('page_name' => 'Home'),
array('page_name' => 'About us', 'level_one' => array('first1','first2', 'level_two' => array('second'), 'first3')),
array('page_name' => 'Gallery', 'level_one' => array('first1','first2','first3','first4')),
array('page_name' => 'Contact us')
);
My code to retrieve the navigation so far is...
$count = count($pages);
for ($x=0; $x<$count; $x++) {
# echo yes for active page
if ($filename == $pages[$x][1]) { echo 'yes'; }
# echo main navigation
echo $pages[$x]['page_name'];
# check if the item has a sub page
$firstcount = count($pages[$x]['level_one']);
# if the item has a sub page echo
if ($firstcount > 0) { for ($y=0; $y<$firstcount; $y++) {
echo "\r\n" . '.' . $pages[$x]['level_one'][$y];
# check if the page has a sub page
$secondcount = count($pages[$x]['level_one']['level_two']);
if ($secondcount > 0) { for ($z=0; $z<$secondcount; $z++) {
if($pages[$x]['level_one']['level_two'][$z] != '') { echo "\r\n" . '..' . $pages[$x]['level_one']['level_two'][$z]; }
}}
} }
echo "\r\n";
}
And the output I'm currently getting is...
Home
About us
.first1
..second
.first2
..second
.first3
..second
.
..second
Gallery
.first1
.first2
.first3
.first4
Contact us
I am trying to create a multi level navigation. My expected output would be...
<!-- Expected output
Home
About us
.first1
.first2
..second
.first3
Gallery
.first1
.first2
.first3
.first4
Contact us
-->