Skip to content

Instantly share code, notes, and snippets.

@sarpdorukaslan
Last active March 7, 2016 13:25
Show Gist options
  • Save sarpdorukaslan/71269cdc57a8312a539a to your computer and use it in GitHub Desktop.
Save sarpdorukaslan/71269cdc57a8312a539a to your computer and use it in GitHub Desktop.
Convert multi dimensional array to one dimensional array.
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