I am using following code to generate menus
<?php
$menu = array();
$menu['home'] = 'Home';
$menu['mypage'] = 'My Page';
//Add in the format of: $menu['page name'] = 'Page Title';
$title='Home'; //Default title
function generateMenu() {
global $menu,$default,$title;
echo ' <ul>';
$p = isset($_GET['p']) ? $_GET['p'] : $default;
foreach ($menu as $link=>$item) {
$class='';
if ($link==$p) {
$class=' class="selected"';
$title=$item;
}
echo '<li><a href="?p='.$link.'"'.$class.'>'.$item.'</a></li>';
}
echo '</ul>';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My PHP Template - <?php echo $title; ?></title>
</head>
<body>
<?php
generateMenu();
$default = 'home'; //Whatever default page you want to display if the file doesn't exist or you've just arrived to the home page.
$page = isset($_GET['p']) ? $_GET['p'] : $default; //Checks if ?p is set, and puts the page in and if not, it goes to the default page.
if (!file_exists('inc/'.$page.'.php')) { //Checks if the file doesn't exist
$page = $default; //If it doesn't, it'll revert back to the default page
//NOTE: Alternatively, you can make up a 404 page, and replace $default with whatever the page name is. Make sure it's still in the inc/ directory.
}
include('inc/'.$page.'.php'); //And now it's on your page!
?>
</body>
</html>
But I have 6 menus and first three menu have sub menus. Above code generates only menus. I want to add sub menu also.
Can anyone tell me HOW TO SOLVE THIS?