What are the potential pitfalls of using scandir() in PHP scripts?

One potential pitfall of using scandir() in PHP scripts is that it may return unexpected results if the directory being scanned contains hidden files or directories (those starting with a dot). To avoid this issue, you can filter out hidden files and directories by using a simple conditional statement to exclude them from the results.

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

foreach($files as $file) {
    if($file[0] != '.') {
        // Process the file
    }
}