In what scenarios would using scandir() be more efficient than RecursiveDirectoryIterator for directory search operations in PHP?

Scandir() may be more efficient than RecursiveDirectoryIterator for directory search operations in PHP when you only need a list of filenames in a directory without recursively searching subdirectories. Scandir() is a simpler and faster function compared to RecursiveDirectoryIterator, which traverses through all subdirectories. If you only need filenames in a single directory, scandir() can be a more efficient choice.

$directory = '/path/to/directory';

// Using scandir() to get list of filenames in a directory
$files = scandir($directory);

foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
        echo $file . "\n";
    }
}