What is the best way to alphabetically sort directories and subdirectories in PHP?

When sorting directories and subdirectories alphabetically in PHP, we can use the `scandir()` function to retrieve a list of files and directories within a specified directory. We can then filter out the '.' and '..' directories and sort the remaining directories using the `sort()` function.

$dir = "path/to/directory";

$files = array_diff(scandir($dir), array('..', '.'));

sort($files);

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