Skip to content

Instantly share code, notes, and snippets.

@pacmanito
Created April 26, 2020 07:52
Show Gist options
  • Save pacmanito/15287f109817ab3ae27c3e73f5887d20 to your computer and use it in GitHub Desktop.
Save pacmanito/15287f109817ab3ae27c3e73f5887d20 to your computer and use it in GitHub Desktop.
Multi-dimensional array iterator
$data = array(/* multi-dimensional */);
$result = iterate($data);
function iterate(array $array)
{
$result = array();
foreach($array as $item) {
if(is_array($item)) {
$result[] = iterate($item);
} else {
$changed = $item; // do something to the value.
$result[] = $changed;
}
}
return $result;
}
@pacmanito
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment