Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save autotrof/abb914ef13c0b2881a9f108f49a8d2b5 to your computer and use it in GitHub Desktop.
Save autotrof/abb914ef13c0b2881a9f108f49a8d2b5 to your computer and use it in GitHub Desktop.
get from Arr::dot in laravel. just little modification
function form_array($array, $prepend='')
{
$results = [];
foreach ($array as $key => $value) {
if (is_array($value) && ! empty($value)) {
if($prepend==''){
$results = array_merge($results, form_array($value, $key));
}else{
$results = array_merge($results, form_array($value, $prepend.'['.$key.']'));
}
} else {
if(is_array($value) && count($value)==0) $value = "[]";
if($prepend==''){
$results[$key] = $value;
}else{
$results[$prepend.'['.$key.']'] = $value;
};
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment