How does the glob function with the GLOB_ONLYDIR flag compare to using scandir for listing directories in PHP?

When using the glob function with the GLOB_ONLYDIR flag, it will only return directories in the specified path, while scandir will return all files and directories. This can be useful if you only need to list directories without having to filter out files manually.

// Using glob with GLOB_ONLYDIR flag
$directories = glob('/path/to/directory/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
    echo $directory . PHP_EOL;
}