Skip to content

Instantly share code, notes, and snippets.

@yassine-khachlek
Last active July 30, 2016 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yassine-khachlek/4200f0f9baeda1683597d52fc6738747 to your computer and use it in GitHub Desktop.
Save yassine-khachlek/4200f0f9baeda1683597d52fc6738747 to your computer and use it in GitHub Desktop.
function flatten_multidimensional_array($array, $parentKey = NULL, $output = NULL )
{
$parentKey = isset($parentKey) ? $parentKey.'_' : '';
$output = isset($output) ? $output : array();
foreach ($array as $key => $value)
{
switch (gettype($value))
{
case "string":
$output[$parentKey.$key] = $value;
break;
default:
$output = array_merge($output, flatten_multidimensional_array($value, $parentKey.$key, $output));
}
}
return $output;
}
$output = flatten_multidimensional_array($array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment