PHP Get all subdirectories of a given directory

Option 1:

You can use glob() with the GLOB_ONLYDIR option.

Option 2:

Another option is to use array_filter to filter the list of directories. However, note that the code below will skip valid directories with periods in their name like .config.

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

Here is how you can retrieve only directories with GLOB:

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