Created
July 2, 2012 21:34
-
-
Save cam-gists/3035851 to your computer and use it in GitHub Desktop.
PHP: single Dimension Array Iterator
This file contains hidden or 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 | |
// an array (using PHP 5.4's new shorthand notation) | |
$arr = ["sitepoint", "phpmaster", "buildmobile", "rubysource", | |
"designfestival", "cloudspring"]; | |
// create a new ArrayIterator and pass in the array | |
$iter = new ArrayIterator($arr); | |
// loop through the object | |
foreach ($iter as $key => $value) { | |
echo $key . ": " . $value . "<br>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment