PEAR_Config::arrayMergeRecursive PHP Method

arrayMergeRecursive() public method

public arrayMergeRecursive ( $arr2, $arr1 ) : array
return array
    function arrayMergeRecursive($arr2, $arr1)
    {
        $ret = array();
        foreach ($arr2 as $key => $data) {
            if (!isset($arr1[$key])) {
                $ret[$key] = $data;
                unset($arr1[$key]);
                continue;
            }
            if (is_array($data)) {
                if (!is_array($arr1[$key])) {
                    $ret[$key] = $arr1[$key];
                    unset($arr1[$key]);
                    continue;
                }
                $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
                unset($arr1[$key]);
            }
        }
        return array_merge($ret, $arr1);
    }

Usage Example

Beispiel #1
0
 /**
  * @param array
  * @param array
  * @return array
  * @static
  */
 function arrayMergeRecursive($arr2, $arr1)
 {
     $ret = array();
     foreach ($arr2 as $key => $data) {
         if (!isset($arr1[$key])) {
             $ret[$key] = $data;
             unset($arr1[$key]);
             continue;
         }
         if (is_array($data)) {
             if (!is_array($arr1[$key])) {
                 $ret[$key] = $arr1[$key];
                 unset($arr1[$key]);
                 continue;
             }
             $ret[$key] = PEAR_Config::arrayMergeRecursive($arr1[$key], $arr2[$key]);
             unset($arr1[$key]);
         }
     }
     return array_merge($ret, $arr1);
 }