Displays all directories only

<?php
$dir = "*";
foreach(glob($dir) as $file)   {echo $file . "<br />";  }
?>

The code above displays all files and directories.

<?php
$dir = "*.*";
foreach(glob($dir) as $file)   {echo $file . "<br />";  }
?>

The code above displays all files only.

I like to displays all directories only .
The would-be-code below is one of my trials for it, but it seems not to work.

[b]would-be code[/b]
<?php
$dir = "/";
foreach(glob($dir) as $file)   {echo $file . "<br />";  }
?>

Try this:




  <?php 
    echo '<pre>';
// $d = dir("/etc/php5");
    $d = dir(".");
     // echo "Handle: " . $d->handle . "\
";
  // echo "Path: " . $d->path . "\
"; 
    $dd = array();
  $ff = array();
 while (false !== ($entry = $d->read()))
     {
       if('.' !== $entry && '..' !== $entry)
       {
           if( is_dir($entry))
           {
              // echo 'Dir: " ' .$entry."<br />";
               $dd[] = $entry; 
           }else{
               // echo 'file" ' .$entry."<br />";
               $ff[] = $entry; 
           }
       }  
 }
     $d->close();

      echo '<b>Dirs: </b>';  print_r($dd);
      echo '<b>Files: </b>'; print_r($ff);
  echo '</pre>';
?>


Output

Dirs: Array
(
[0] => bin
[1] => pkg
[2] => src
)
Files: Array
(
[0] => style-golang.css
[1] => index.php
[2] => Linux-Cheat-Sheet.pdf
)