recursive dynamic menu

i have a menu i created that works perfect. however i am having trouble understnading how i would make it more dynamic in recurivly searching folders to make sub menu’s of submenu’s.
below is my current code.

[php]
echo"\t\t<ul id=“menu”>\n";
$vdir = “./”;
$menu_items =scandir($vdir);
foreach($menu_items as $languages){
$mclass = “dropdown_2columns”;
$exclude = array(’.’, ‘…’,‘index.php’, ‘js’, ‘style.css’,‘phpqrcode’,‘tracking’);
if(!in_array($languages, $exclude) && is_dir($languages)) {
echo “\t\t\t

  • $languages\n”;
    $languages_folders = scandir($languages);
    if(count($languages_folders) >= 10){
    $mclass = “dropdown_3columns”;
    }
    echo “\t\t\t\t
    \n “;
    foreach($languages_folders as $books){
    $dclass = “col_2”;
    if(count($languages_folders) >= 10){
    $dclass = “col_3”;
    }
    $exclude = array(’.’, ‘…’,‘index.php’, ‘js’, ‘style.css’, ‘tracking’);
    if(!in_array($books, $exclude) && !is_dir($books)) {
    $books = urldecode($books);
    echo “\t\t\t\t\t
    \n\t\t\t\t\t\t$books\n\t\t\t\t\t
    \n”;
    }
    }
    echo”\t\t\t\t
  • \n”;
    }
    }
    if($_SERVER[‘REMOTE_ADDR’] =="$ip"){
    echo “\t\t\t
  • Site Stats
  • \n”;
    }
    echo"\t\t\n";
    [/php]
    which looks two (2) levels deep. how would I make this search X levels deep?

    i have finished this, my end result is as follows:
    [php]function create_menu($fp){
    $exclude = array(’…/.’, ‘…/…’,’…/index.php’, ‘…/js’, ‘…/style.css’,’…/phpqrcode’,’…/tracking’,’…/Script’, ‘…/sessions’,’…/global_v1.css’);
    foreach(new RecursiveDirectoryIterator($fp) as $folder) {
    if(!in_array($folder, $exclude) ){
    if($folder->isDir()){
    $folderid = substr($folder, 3);
    echo “\n\t\t\t

  • \n\t\t\t\t”.$folder."";
    echo “\n\t\t\t\t\t
      ”;
      create_menu($folder);
      echo “\n\t\t\t\t
    ”;
    echo “\n\t\t\t
  • ”;
    }
    		if(!$folder->isDir()){
    			echo "\n\t\t\t\t\t\t<li id=bookslist class=col_2><a href='$folder'>".$folder."</a></li>";
    		}
    		
    	}
    }
    

    }[/php]

    Good job :slight_smile:

    Sponsor our Newsletter | Privacy Policy | Terms of Service