What are the advantages of using the scandir function in PHP 5 for listing directories?

When listing directories in PHP, using the scandir function in PHP 5 can provide advantages such as sorting the results alphabetically, including hidden files, and simplifying the code required to list directories.

// List directories using scandir function
$dir = "/path/to/directory";
$files = scandir($dir);

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