note 90832 added to class.iterator
| From: | RocketInABog at techno-monks dot net | Date: | Tue, 12 May 2009 09:43:08 +0000 |
| Subject: | note 90832 added to class.iterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-154492@lists.php.net to get a copy of this message | ||
This is a comment on chanibal.net posting on the class.iterator.php page (php dot
net/manual/en/class.iterator.php#88560).
I tried the for(;;) iteration example and it didn't iterate the same way as the foreach()
example.
Here is an example for(;;) iteration which is probably what Chanibal intended.
<?php
for( $it->rewind();
$val=$it->current(), $key=$it->key(), $it->valid();
$it->next()
) {
print "{$key}=>{$val}\n";
}
?>
Here is another way/style of coding a for(;;) loop
(if you are not trying to create a for(;;) drop-in replacement for foreach() ).
<?php
# - $iter = an instance of a class implementing the Iterator interface.
for( $iter->rewind(); $iter->valid(); $iter->next() )
{
print "{$iter->key()}=>{$iter->current()}\n";
}
?>
----
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/90832
Del: integrated -- https://master.php.net/note/delete/90832/integrated
Del: useless -- https://master.php.net/note/delete/90832/useless
Del: bad code -- https://master.php.net/note/delete/90832/bad+code
Del: spam -- https://master.php.net/note/delete/90832/spam
Del: non-english -- https://master.php.net/note/delete/90832/non-english
Del: in docs -- https://master.php.net/note/delete/90832/in+docs
Del: other reasons-- https://master.php.net/note/delete/90832
Reject -- https://master.php.net/note/reject/90832
Search -- https://master.php.net/manage/user-notes.php