note 91286 added to language.oop5.iterations

From: Date: Wed, 03 Jun 2009 21:34:04 +0000
Subject: note 91286 added to language.oop5.iterations
Groups: php.notes 
Request: Send a blank email to php-notes+get-156337@lists.php.net to get a copy of this message
<pre>Referring to the note below by <h3>hlegius</h3> :thank's for what you wrote..didn't do the speed test but the way you suggest is faster/nicer to code. But examples 2&3 are good to show how to create a custom interface and then call it when implementing the IteratorAggregate. The following is how to get similar results to ex.2 via ArrayObject class. ref: http://www.php.net/manual/en/class.arrayobject.php </pre> <?php echo "<pre>"; $comp = array('aa','bb','cc'); $compO= new ArrayObject($comp); for($ite=$compO->getIterator();$ite->valid();$ite->next()){ echo "current: ".$ite->current()."\n"; echo "valid: ".$ite->valid()."\n"; echo "key: ".$ite->key()."\n"; echo 'ite is ok'."\n"; } ?> well..it's even more straight ahead by using a new ArrayIterator directly.. ref: http://www.php.net/manual/en/class.arrayiterator.php <?php echo "<pre>"; $comp = array('aa','bb','cc'); $compO= new ArrayIterator($comp); for($compO;$compO->valid();$compO->next()){ echo "current: ".$compO->current()."\n"; echo "valid: ".$compO->valid()."\n"; echo "key: ".$compO->key()."\n"; echo 'compO is ok'."\n"; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 24.68.193.59 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.iterations.php Edit -- https://master.php.net/note/edit/91286 Del: integrated -- https://master.php.net/note/delete/91286/integrated Del: useless -- https://master.php.net/note/delete/91286/useless Del: bad code -- https://master.php.net/note/delete/91286/bad+code Del: spam -- https://master.php.net/note/delete/91286/spam Del: non-english -- https://master.php.net/note/delete/91286/non-english Del: in docs -- https://master.php.net/note/delete/91286/in+docs Del: other reasons-- https://master.php.net/note/delete/91286 Reject -- https://master.php.net/note/reject/91286 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156337) next »