Created
January 14, 2019 02:46
-
-
Save emersonthis/4b105c301b886c7aa8aa458fa10b897b to your computer and use it in GitHub Desktop.
Flatten array
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 | |
function flatten_array($array) { | |
$flatArray = []; | |
foreach ($array as $item) { | |
if (is_array($item)) { | |
$flatArray = array_merge( $flatArray, flatten_array($item) ); | |
} else { | |
$flatArray = array_merge($flatArray, $item); | |
} | |
} | |
return $flatArray; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment