Created
December 1, 2022 04:34
-
-
Save ydenissov/5ef2148ba7afd25521de6b9352ea4fbc to your computer and use it in GitHub Desktop.
Array merge recursive with save key
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
<?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