note 88560 added to class.iterator

From: Date: Thu, 29 Jan 2009 04:11:51 +0000
Subject: note 88560 added to class.iterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-149929@lists.php.net to get a copy of this message
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"; } ?> ---- Server IP: 82.177.164.100 Probable Submitter: 78.88.223.42 ---- Manual Page -- http://www.php.net/manual/en/class.iterator.php Edit -- https://master.php.net/note/edit/88560 Del: integrated -- https://master.php.net/note/delete/88560/integrated Del: useless -- https://master.php.net/note/delete/88560/useless Del: bad code -- https://master.php.net/note/delete/88560/bad+code Del: spam -- https://master.php.net/note/delete/88560/spam Del: non-english -- https://master.php.net/note/delete/88560/non-english Del: in docs -- https://master.php.net/note/delete/88560/in+docs Del: other reasons-- https://master.php.net/note/delete/88560 Reject -- https://master.php.net/note/reject/88560 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149929) next »