Last active
July 30, 2016 19:47
-
-
Save yassine-khachlek/4200f0f9baeda1683597d52fc6738747 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
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