I have a huge PHP array that contains the navigation structure of the site. It basically looks like this:
$navMap = array(
array(
'title' => 'Home',
), array(
'title' => 'about us',
'subNav' => array(
array(
'title' => 'Sub item 1',
'subNav' => array(
array(
'title' => 'Sub sub item 1',
), array (
'title' => 'Sub sub item 2',
)
),
), array (
'title' => 'Sub item 2',
), array (
'title' => 'Sub item 3',
)
)
)
);
I have a folder structure that will link to "Sub sub item 2" /pages/1/0/1.php, as it is in the second of the primary nav elements, the first of the secondary navigation elements and the second of the tertiary navigation elements.
Instead of writing links to an array that is prone to human error, I use PHP to add links for me. This is what I am doing at the moment:
for ($a = 0; $a < count($navMap); $a++) {
$navMap[$a]['link'] = '/pages/'.$a.'.php';
if (isset($navMap[$a]['subNav'])){
for ($b = 0; $b < count($navMap[$a]['subNav']); $b++) {
$navMap[$a]['subNav'][$b]['link'] = '/pages/'.$a.'/'.$b.'.php';
if (isset($navMap[$a]['subNav'][$b]['subNav'])){
for ($c = 0; $c < count($navMap[$a]['subNav'][$b]['subNav']); $c++) {
$navMap[$a]['subNav'][$b]['subNav'][$c]['link'] = '/pages/'.$a.'/'.$b.'/'.$c.'.php';
}
}
}
}
}
This is a really ugly solution. Does anyone know a better way to add array references?
, , . , $navMap.