flatten(array $array, $keyPrefix = ''): array
{
$return = [];
foreach ($array as $key => $value) {
$key = trim($keyPrefix . '_' . $key, '_');
if (is_array($value)){
$return = array_merge($return, flatten($value, $key));
} else {
$return[$key] = $value;
}
}
return $return;
}
Created
December 29, 2021 13:01
-
-
Save maxcelos/6f1b8acd45d97068bceb4c5d4f5f61da to your computer and use it in GitHub Desktop.
Convert multidimensional array to simple array with keys
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment