How can the use of the `glob()` function in PHP facilitate the retrieval of directories for recursive file operations?

When performing recursive file operations in PHP, it is often necessary to retrieve a list of directories within a given directory. The `glob()` function in PHP can facilitate this by allowing us to easily retrieve a list of directories matching a specified pattern. By using `glob()` with the `GLOB_ONLYDIR` flag, we can specifically target directories and ignore files, making it easier to perform recursive operations on directories only.

// Retrieve a list of directories within a given directory for recursive file operations
$directories = glob('/path/to/directory/*', GLOB_ONLYDIR);

foreach ($directories as $directory) {
    // Perform operations on each directory found
    echo $directory . PHP_EOL;
}