note 86935 added to class.arrayiterator
| From: | VenelinVulkov at osu1 dot php dot net | Date: | Tue, 11 Nov 2008 11:44:02 +0000 |
| Subject: | note 86935 added to class.arrayiterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146380@lists.php.net to get a copy of this message | ||
Another fine Iterator from php . You can use it especially when you have to iterate over objects
<?php
$fruits = array(
"apple" => "yummy",
"orange" => "ah ya, nice",
"grape" => "wow, I love it!",
"plum" => "nah, not me"
);
$obj = new ArrayObject( $fruits );
$it = $obj->getIterator();
// How many items are we iterating over?
echo "Iterating over: " . $obj->count() . " values\n";
// Iterate over the values in the ArrayObject:
while( $it->valid() )
{
echo $it->key() . "=" . $it->current() . "\n";
$it->next();
}
// The good thing here is that it can be iterated with foreach loop
foreach ($it as $key=>$val)
echo $key.":".$val."\n";
/* Outputs something like */
Iterating over: 4 values
apple=yummy
orange=ah ya, nice
grape=wow, I love it!
plum=nah, not me
?>
Regards.
----
Server IP: 128.39.198.38
Probable Submitter: 193.142.0.1
----
Manual Page -- http://www.php.net/manual/en/class.arrayiterator.php
Edit -- https://master.php.net/note/edit/86935
Del: integrated -- https://master.php.net/note/delete/86935/integrated
Del: useless -- https://master.php.net/note/delete/86935/useless
Del: bad code -- https://master.php.net/note/delete/86935/bad+code
Del: spam -- https://master.php.net/note/delete/86935/spam
Del: non-english -- https://master.php.net/note/delete/86935/non-english
Del: in docs -- https://master.php.net/note/delete/86935/in+docs
Del: other reasons-- https://master.php.net/note/delete/86935
Reject -- https://master.php.net/note/reject/86935
Search -- https://master.php.net/manage/user-notes.php