i am trying to store all the pages of a site in a 3 dimensional array. some areas of the site only have 2 levels, others 3. i am trying to check for the existence of a third level in order to pass the right page name to an include. where a 3rd level is not found i want a default page to be shown.
i am using array_key_exists() to check but am not getting the result i am expecting...
<?php
$pages = array (
"news" => array ( '1' => 'latest',
'2' => 'archived',
'3' => array ( '1' => 'photos',
'2' => 'media'
),
),
"about" => array ( '1' => 'history',
'2' => 'strategic',
'3' => array ( '1' => 'management',
'2' => 'board',
'3' => 'contract'
),
),
"services" => array ( '1' => array ( '1' => 'project management case study'),
'2' => array ( '1' => 'track renewals case study'),
'3' => array ( '1' => 'signal installation case study'),
),
);
if (@array_key_exists($pages['about']['3']['1']))
{
echo "array key found";
echo "<br>";
echo $pages['about']['3']['1'];
}
else {
echo "array key does not exist";
echo "<br>";
}
?>
the key clearly exists yet the if loop always returns 'array key does not exist' - what have i done wrong??
ps. i suppressed the following warning message:
Warning: Wrong parameter count for array_key_exists()