public static function merge(array $array1, array $array2, $overwrite = true)
    {
        foreach ($array2 as $key => $value) {
            if (isset($array1[$key])) {
                if (self::isArray($array1[$key]) && self::isArray($value)) {
                    $array1[$key] = self::merge($array1[$key], $value, $overwrite);
                } elseif ($overwrite) {
                    $array1[$key] = $value;
                }
            } else {
                $array1[$key] = $value;
            }
        }

        return $array1;
    }
public static function merge(array $array1, array $array2, $overwrite = true)
    {
        foreach ($array2 as $key => $value) {
            if (isset($array1[$key])) {
                if (self::isArray($array1[$key]) && self::isArray($value)) {
                    $array1[$key] = self::merge($array1[$key], $value, $overwrite);
                } elseif ($overwrite) {
                    $array1[$key] = $value;
                }
            } else {
                $array1[$key] = $value;
            }
        }

        return $array1;
    }
public static function merge ( array $ array1 , array $ array2 , $ overwrite = true ) { foreach ( $ array2 as $ key => $ value ) { if ( isset ( $ array1 [ $ key ] ) ) { if ( self :: isArray ( $ array1 [ $ key ] ) && self :: isArray ( $ value ) ) { $ array1 [ $ key ] = self :: merge ( $ array1 [ $ key ] , $ value , $ overwrite ) ; } elseif ( $ overwrite ) { $ array1 [ $ key ] = $ value ; } } else { $ array1 [ $ key ] = $ value ; } } return $ array1 ; }
Merge two arrays recursively.

@param array $array1
@param array $array2
@param bool  $overwrite Overwrite value if it exists in $array1.

@return array The merged array
Merge two arrays recursively .