note 88560 deleted from class.iterator by salathe

From: Date: Tue, 31 Jul 2012 08:09:46 +0000
Subject: note 88560 deleted from class.iterator by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189526@lists.php.net to get a copy of this message
Note Submitter: http://chanibal.net ---- For anyone interested in how exactly does a iterator work in a foreach: <?php class SomeIterator implements Iterator {/*...implement...*/} $it=new SomeIterator(); foreach($it as $key => $val) { print "{$key}=>{$val}\n"; } // works exactly the same as $it=new SomeIterator(); for( $it->rewind(); $it->valid(); $val=$it->current(), $key=$it->key(), $it->next() ) { print "{$key}=>{$val}\n"; } // and if someone forgot how for(;;) works... $it=new SomeIterator(); $it->rewind; while($it->valid()) { $val=$it->current(); $key=$it->key(); $it->next(); print "{$key}=>{$val}\n"; } ?>

« previous php.notes (#189526) next »