How can the use of "." and ".." affect file counting in PHP?

When counting files in a directory using PHP, the use of "." and ".." can affect the count because these special directories represent the current directory and the parent directory, respectively. To accurately count only the actual files in a directory, you can filter out these special directories from the count.

$directory = "path/to/directory";
$fileCount = count(array_diff(scandir($directory), array('.', '..')));
echo "Number of files in directory: " . $fileCount;