I think this may be the fastest way to get a list of all the directories in a given folder/directory using PHP.

I needed this when building a plugin system where each plugin lived in its own subdirectory. The glob() function with array_filter and is_dir is a clean one-liner that avoids the overhead of scandir plus manual filtering. If you need to go recursive, look into RecursiveDirectoryIterator instead — but for a single level of directories, this approach is hard to beat.

$directories = array_filter(glob('*'), 'is_dir');

..and of course, you can also add a path to it if you need to:

$directories = array_filter(glob($myPath.'*'), 'is_dir');