In PHP, what best practice should be followed when iterating through directories to count files?

When iterating through directories to count files in PHP, it is best practice to use the `glob` function along with the `count` function to efficiently count the number of files in a directory. This method allows you to easily filter out directories and count only the files within the specified directory.

$directory = 'path/to/directory';
$files = glob($directory . '/*');
$fileCount = count($files);

echo "Number of files in directory: " . $fileCount;