Skip to content

Instantly share code, notes, and snippets.

@craiga
Last active December 18, 2015 22:29
Show Gist options
  • Save craiga/5855194 to your computer and use it in GitHub Desktop.
Save craiga/5855194 to your computer and use it in GitHub Desktop.
<?php
/**
* Flatten an array, preserving keys.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/5855194
*/
function flattenArray($in) {
$out = array();
foreach($in as $key => $value) {
if(is_array($value)) {
$out = array_merge($out, flattenArray($value));
}
else {
$out[$key] = $value;
}
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment