Newscoop\NewscoopBundle\DependencyInjection\NewscoopNewscoopExtension::array_merge_recursive_distinct PHP 메소드

array_merge_recursive_distinct() 개인적인 메소드

array_merge_recursive(array('key' => 'org value'), array('key' => 'new value')); => array('key' => array('org value', 'new value')); array_merge_recursive_distinct does not change the datatypes of the values in the arrays. Matching keys' values in the second array overwrite those in the first array, as is the case with array_merge, i.e.: array_merge_recursive_distinct(array('key' => 'org value'), array('key' => 'new value')); => array('key' => 'new value'); Parameters are passed by reference, though only for performance reasons. They're not altered by this function.
private array_merge_recursive_distinct ( array &$array1, mixed &$array2 = null ) : array
$array1 array
$array2 mixed
리턴 array
    private function &array_merge_recursive_distinct(array &$array1, &$array2 = null)
    {
        $merged = $array1;
        if (is_array($array2)) {
            foreach ($array2 as $key => $val) {
                if (is_array($array2[$key])) {
                    $mergedKey = !empty($merged[$key]) ? $merged[$key] : null;
                    $arrayKey = $array2[$key];
                    $merged[$key] = is_array($mergedKey) ? $this->array_merge_recursive_distinct($mergedKey, $arrayKey) : $arrayKey;
                } else {
                    $merged[$key] = $val;
                }
            }
        }
        return $merged;
    }