Created
April 26, 2020 07:52
-
-
Save pacmanito/15287f109817ab3ae27c3e73f5887d20 to your computer and use it in GitHub Desktop.
Multi-dimensional array iterator
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
$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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from here - https://stackoverflow.com/questions/24383437/recursive-foreach-loop-i-think