Skip to content

Instantly share code, notes, and snippets.

@ydenissov
Created December 1, 2022 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydenissov/5ef2148ba7afd25521de6b9352ea4fbc to your computer and use it in GitHub Desktop.
Save ydenissov/5ef2148ba7afd25521de6b9352ea4fbc to your computer and use it in GitHub Desktop.
Array merge recursive with save key
<?php
function array_merge_recursive_save_keys() {
$arrays = func_get_args();
$base = array_shift($arrays);
foreach ($arrays as $array) {
reset($base);
foreach($array as $key => $value) {
if (is_array($value) && @is_array($base[$key])) {
$base[$key] = self::array_merge_recursive_save_keys($base[$key], $value);
} else {
$base[$key] = $value;
}
}
}
return $base;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment