Can you provide an example code snippet in PHP for counting files with a specific file extension in a folder?

To count files with a specific file extension in a folder using PHP, we can iterate through all the files in the folder and check if each file has the desired file extension. We can use the glob() function to get an array of all files with a specific extension in the folder, and then count the number of elements in the array to determine the total count.

$folder = 'path/to/folder';
$extension = 'txt';

$files = glob($folder . '/*.' . $extension);
$fileCount = count($files);

echo "Number of .$extension files in $folder: $fileCount";