PHP readdir() not returning files in alphabetical order
Solution 1:
Alphabetical order :: I think you misread the snippet you quoted...
Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.
The fact that 'ls' would display the files in (usually) alphabetical order does not mean that's how they are stored on the filesystem. PHP is behaving as spec, I'm afraid.
You may want to consider using scandir as the basis for your efforts, if alphabetical sorting is a must. :)
Solution 2:
You could copy all the filenames into an array and then use
<?php
sort($filesArray);
?>
Solution 3:
i suppose docs are quite clear here.
order in which they are stored in filesystem
is not the same as alphabetic order
Solution 4:
You're misreading the docs:
The filenames are returned in the order in which they are stored by the filesystem.
means that files are returned in the order they were created.