PHP Get all subdirectories of a given directory PHP Get all subdirectories of a given directory php php

PHP Get all subdirectories of a given directory


you can use glob() with GLOB_ONLYDIR option

or

$dirs = array_filter(glob('*'), 'is_dir');print_r( $dirs);


Here is how you can retrieve only directories with GLOB:

$directories = glob($somePath . '/*' , GLOB_ONLYDIR);


The Spl DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.

$dir = new DirectoryIterator($path);foreach ($dir as $fileinfo) {    if ($fileinfo->isDir() && !$fileinfo->isDot()) {        echo $fileinfo->getFilename().'<br>';    }}