I'll be the first to admit that PHP is not my forte and this array is starting to drive me nuts.
This is the array I'm attempting to enumerate:
// array containing the site menu
$sitemap = array(
array( 'Title' => 'menu01',
'Description' => 'menu01_description',
'Address' => 'http://localhost/site.php?page=menu01',
),
array( 'Title' => 'menu02',
'Description' => 'menu02_description',
'Address' => 'http://localhost/site.php?page=menu02',
),
array( 'Title' => 'menu03',
'Description' => 'menu03_description',
'Address' => 'http://localhost/site.php?page=menu03',
)
);
Right now I'm operating under the assumption that I need to use a foreach loop to enumerate the contents of my array.
This is the function I'm currently trying to implement, but it keeps returning an error stating that my arguments are not valid.
function GenerateMenu(){
$output = "<ul>";
foreach ($sitemap as $menuitem => $value){
if ($page == $value["Title"]){
$output .= '<li class="active">';
}
else {
$output .= '<li>';
}
$output .= '<a href="' . $value['Address'] . '">' . $value['Description'] . '</a><li>';
}
$output .= "</ul>";
return $output;
}
Why are my arguments invalid? What best way to print my array?