Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created July 2, 2012 21:36
Show Gist options
  • Select an option

  • Save cam-gists/3035865 to your computer and use it in GitHub Desktop.

Select an option

Save cam-gists/3035865 to your computer and use it in GitHub Desktop.
PHP: Multi Dimensional Array Iterator
<?php
// a multidimensional array
$arr = [
["sitepoint", "phpmaster"],
["buildmobile", "rubysource"],
["designfestival", "cloudspring"],
"not an array"
];
// loop through the object
foreach ($arr as $key => $value) {
// check for arrays
if (is_array($value)) {
foreach ($value as $k => $v) {
echo $k . ": " . $v . "<br>";
}
}
else {
echo $key . ": " . $value . "<br>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment