note 90832 deleted from class.iterator by danbrown

From: Date: Tue, 12 May 2009 12:38:17 +0000
Subject: note 90832 deleted from class.iterator by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154500@lists.php.net to get a copy of this message
Note Submitter: RocketInABog at techno-monks dot net ---- 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"; } ?>

« previous php.notes (#154500) next »