What PHP function was recommended to the user to handle reading directories and files more efficiently?

The user was recommended to use the PHP function `scandir()` to handle reading directories and files more efficiently. This function returns an array of files and directories in the specified directory, eliminating the need for multiple `opendir()` and `readdir()` calls.

// Example of using scandir() to read directories and files
$directory = "/path/to/directory";
$files = scandir($directory);

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