I want to add a class=active to the current page im on with php
class_navigation.php
$menu = array(
'home' => array('text'=>'Home', 'url'=>'?p=home'),
'away' => array('text'=>'About', 'url'=>'?p=about'),
'about' => array('text'=>'Contact', 'url'=>'?p=contact'),
);
class class_navigation {
public static function GenerateMenu($items) {
$html = "<nav>\n";
foreach($items as $item) {
$class ="";
if ($page == $item) {
$class = "class='active'";
}
$html .= "<a href='{$item['url']}' ".$class.">{$item['text']}
</a>\n";
}
$html .= "</nav>\n";
return $html;
}
};
nav.php
<?php
echo class_navigation::GenerateMenu($menu);
?>
index.php
require_once('class/class_navigation.php');
require_once('includes/head.php');
require_once('includes/nav.php');
switch($_GET['p']){
case "home":
$page = 'home';
include_once('pages/home.php');
break 1;
case "about":
$page = "about";
include_once('pages/about.php');
break 1;
case "contact":
$page = "contact";
include_once('pages/contact.php');
break 1;
}
require_once('includes/footer.php');
$html .= "<a href='{$item['url']}' ".$class.">{$item['text']} </a>\n";? where$class = 'class="active"';