Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created July 2, 2012 21:34
Show Gist options
  • Save cam-gists/3035851 to your computer and use it in GitHub Desktop.
Save cam-gists/3035851 to your computer and use it in GitHub Desktop.
PHP: single Dimension Array Iterator
<?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