I noticed that FilesystemIterator returns the files ordered by name. Can anyone confirm this is true and it always happens? I haven't found anything in the docs.
You can't sort data which comes from an Iterator. Why? Because an Iterator is lazy with the data handling, that means the iterator only knows about 1 item at the time.
So the Iterator doesn't sort the files in any way and you can't sort the data directly from an iterator, you would have to save it into an array or so to be able to sort the data.
Another question, is there any way to get the files ordered by the creation time on the disk?
usort()
is a good idea, but not with DirectoryIterator::getCTime()
, because this is a method of the iterator. But you can use: filemtime()
(Just be aware of that the function is cached!)