What best practice should be followed when using scandir() to read directory contents in PHP?

When using scandir() to read directory contents in PHP, it is best practice to check for the "." and ".." entries in the result array before processing the files. These entries represent the current directory and the parent directory, respectively, and should be excluded from any further operations to avoid errors.

$directory = "path/to/directory";
$files = scandir($directory);

foreach ($files as $file) {
    if ($file != "." && $file != "..") {
        // Process the file here
    }
}