What is the best way to display the number of files in a directory using PHP?

To display the number of files in a directory using PHP, you can use the `scandir()` function to scan the directory and then count the number of files returned by the function. This will give you an accurate count of the files in the directory.

$directory = "path/to/directory";
$files = scandir($directory);
$numFiles = count($files) - 2; // Subtract 2 to account for '.' and '..'

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