Created
April 8, 2016 19:13
-
-
Save michaelvandenberg/40df9d2c3ecb70fc59d9a7314c075353 to your computer and use it in GitHub Desktop.
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
/** | |
* Turn a multi-dimensional array in to a simple flat array. | |
* | |
* @link http://stackoverflow.com/a/14972714/4429450 | |
*/ | |
function array_flatten($array) { | |
$return = array(); | |
foreach ($array as $key => $value) { | |
if (is_array($value)){ $return = array_merge($return, array_flatten($value));} | |
else {$return[$key] = $value;} | |
} | |
return $return; | |
} | |
$result = array_flatten( $unflattened_array ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment