Skip to content

Instantly share code, notes, and snippets.

@MichaelVanDenBerg
Created April 8, 2016 19:13
Show Gist options
  • Save MichaelVanDenBerg/40df9d2c3ecb70fc59d9a7314c075353 to your computer and use it in GitHub Desktop.
Save MichaelVanDenBerg/40df9d2c3ecb70fc59d9a7314c075353 to your computer and use it in GitHub Desktop.
/**
* 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