Is there a simple way to sort an iterator in PHP (without just pulling it all into an array and sorting that).
The specific example I have is a DirectoryIterator but it would be nice to have a solution general to any iterator.
$dir = new DirectoryIterator('.');
foreach ($dir as $file)
echo $file->getFilename();
I'd like to be able to sort these by various criteria (filename, size, etc)
There is no way to do that. An iterator should "iterate" through the list. You have to sort the underlying list to achieve the needed behavior.
By the way, the more complete reference to the SPL is here: http://www.php.net/~helly/php/ext/spl/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With