note 90830 added to class.iterator
| From: | RocketInABog at techno-monks dot net | Date: | Mon, 11 May 2009 23:35:33 +0000 |
| Subject: | note 90830 added to class.iterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154489@lists.php.net to get a copy of this message | ||
<?php
# - Here is an implementation of the Iterator interface for arrays
# which works with maps (key/value pairs)
# as well as traditional arrays
# (contiguous monotonically increasing indexes).
# Though it pretty much does what an array
# would normally do within foreach() loops,
# this class may be useful for using arrays
# with code that generically/only supports the
# Iterator interface.
# Another use of this class is to simply provide
# object methods with tightly controlling iteration of arrays.
class tIterator_array implements Iterator {
private $myArray;
public function __construct( $givenArray ) {
$this->myArray = $givenArray;
}
function rewind() {
return reset($this->myArray);
}
function current() {
return current($this->myArray);
}
function key() {
return key($this->myArray);
}
function next() {
return next($this->myArray);
}
function valid() {
return key($this->myArray) !== null;
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 75.72.168.175
----
Manual Page -- http://www.php.net/manual/en/class.iterator.php
Edit -- https://master.php.net/note/edit/90830
Del: integrated -- https://master.php.net/note/delete/90830/integrated
Del: useless -- https://master.php.net/note/delete/90830/useless
Del: bad code -- https://master.php.net/note/delete/90830/bad+code
Del: spam -- https://master.php.net/note/delete/90830/spam
Del: non-english -- https://master.php.net/note/delete/90830/non-english
Del: in docs -- https://master.php.net/note/delete/90830/in+docs
Del: other reasons-- https://master.php.net/note/delete/90830
Reject -- https://master.php.net/note/reject/90830
Search -- https://master.php.net/manage/user-notes.php