To create many links / menu with a few code, we can looping it from array data. First, we hold the link and also it text into associative array. Here is the simple code:
<html>
<head>
<title>Create Menu with PHP Associative Array</title>
</head>
<body>
<h2>Create Menu with PHP Associative Array</h2>
<ul>
<?php
//create php asociative array hold in $a variable (as example we create 4 menu : Home, Profile, Gallery, Guestbook)
$a = array("index.php"=>"Home", "index.php?pg=profile"=>"Profile", "index.php?pg=gallery"=>"Gallery", "index.php?pg=guestbook"=>"Guestbook");
//loop data
foreach($a as $link=>$text){
//print links
echo "<li><a href='".$link."'>".$text."</a></li>";
}
?>
</ul>
</body>
</html>
Post by : Oka Dayendra
Post on : 24 July 2011
File : menu-with-php-associative-array.zip, size : 519 bytes
Title : Create Menu With PHP Associative Array
Category : PHP
Source : http://www.leakbali.com