Last active
March 7, 2016 13:25
-
-
Save sarpdorukaslan/71269cdc57a8312a539a to your computer and use it in GitHub Desktop.
Convert multi dimensional array to one dimensional array.
This file contains 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 arrayConvertKeyValue($array,$prefix=null) | |
{ | |
$tempArray = array(); | |
$childArray = array(); | |
foreach($array as $key => $value) | |
{ | |
$key = $prefix.".".$key; | |
if(is_array($value)) | |
{ | |
$childArray = arrayConvertKeyValue($value,$key); | |
} | |
else | |
{ | |
$key = trim($key,"."); | |
$tempArray[$key] = $value; | |
} | |
$tempArray = array_merge($tempArray,$childArray); | |
} | |
return $tempArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment