I need to sort the contents of a directory in ascending order (alphabetically). The directories must appear before files even if the directory's name would appear after a files name (alphabetically). The same way file explorers do, they list directories sorted then they list the files sorted.
I am using the following code which gives me a sorted list alphabetically but it does not advances the directories first:
if($handler = opendir($dir))
{
while (($sub = readdir($handler)) !== FALSE)
{
// ...
}
closedir($handler);
}