note 91286 deleted from language.oop5.iterations by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Jun 2009 21:34:51 +0000 |
| Subject: | note 91286 deleted from language.oop5.iterations by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156338@lists.php.net to get a copy of this message | ||
Note Submitter: rskret at gmail dot com
----
<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";
}
?>