note 104735 added to class.directoryiterator
| From: | sergey dot tsivin at NOSPAM dot com | Date: | Mon, 04 Jul 2011 14:01:20 +0000 |
| Subject: | note 104735 added to class.directoryiterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181224@lists.php.net to get a copy of this message | ||
Here's a way to create sortable iterator, thanks to Philipp W. gnurepublic_at_linuxmail.org and
Michelangelo van Dam.
<?php
class SortableDirectoryIterator implements IteratorAggregate
{
private $_storage;
public function __construct($path)
{
$this->_storage = new ArrayObject();
$files = new DirectoryIterator($path);
foreach ($files as $file) {
$this->_storage->offsetSet($file->getFilename(), $file->getFileInfo());
}
$this->_storage->uksort(
function ($a, $b) {
return strcmp($a, $b);
}
);
}
public function getIterator()
{
return $this->_storage->getIterator();
}
}
?>
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/class.directoryiterator.php
Edit -- https://master.php.net/note/edit/104735
Del: integrated -- https://master.php.net/note/delete/104735/integrated
Del: useless -- https://master.php.net/note/delete/104735/useless
Del: bad code -- https://master.php.net/note/delete/104735/bad+code
Del: spam -- https://master.php.net/note/delete/104735/spam
Del: non-english -- https://master.php.net/note/delete/104735/non-english
Del: in docs -- https://master.php.net/note/delete/104735/in+docs
Del: other reasons-- https://master.php.net/note/delete/104735
Reject -- https://master.php.net/note/reject/104735
Search -- https://master.php.net/manage/user-notes.php