Last active
May 8, 2017 13:09
-
-
Save DavMorr/cafcf59dd93b497f7a8e to your computer and use it in GitHub Desktop.
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
function array_merge_recursive_ex(array & $array1, array & $array2) | |
{ | |
$merged = $array1; | |
foreach ($array2 as $key => & $value) | |
{ | |
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) | |
{ | |
$merged[$key] = array_merge_recursive_ex($merged[$key], $value); | |
} else if (is_numeric($key)) | |
{ | |
if (!in_array($value, $merged)) | |
$merged[] = $value; | |
} else | |
$merged[$key] = $value; | |
} | |
return $merged; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment