What are some potential pitfalls when using scandir() to list files in a directory in PHP?

One potential pitfall when using scandir() is that it includes special entries like "." and ".." in the list of files, which may not be desirable. To avoid this, you can filter out these entries from the result array before using them.

$directory = "/path/to/directory";
$files = array_diff(scandir($directory), array('.', '..'));

foreach ($files as $file) {
    echo $file . "<br>";
}