Created
November 7, 2014 12:14
-
-
Save cezar62882/eb533b7f6ede45b23453 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment