I am working on a dynamic menu system as the site I'm build has a strict naming convention.
For example, if I have a script are named AboutUs.php
, then 'About Us' will be a Parent Menu Item. However if I have a script named Product.Product1.php
then 'Product' is the Parent Item with 'Product1' as the Sub Menu Item.
The idea is to loop through grabbing all the scripts in my frontend folder and build an array so the ul/li elements can be echoed using a nested foreach
I just can't seem to get the Array
and the $submenu)
just right.. Thanks!
if ($handle = opendir('frontend/')) {
while(false !== ($sFile = readdir($handle))) {
if (strrpos($sFile, ".php") === strlen($sFile)-strlen(".php")) {
$pos1 = strrpos($sFile, ".");
$menu = substr($sFile, 0, $pos1);
$pos2 = strrpos($sFile, ".php");
if ($pos1 == $pos2) { // "." and ".php" where in the pos, skip submenu
$links[$menu] = 'fontend/'.$sFile;
} else {
$submenu = substr($sFile, $pos1, $pos2);
$links[$menu][$submenu] = 'fontend/'.$sFile;
}
}
}
}