src/Subscribo/Support/Arr.php
public static function mergeNatural(array $array1, array $array2)
    {
        if (empty($array1)) {
            return $array2;
        }
        $result = $array1;
        foreach ($array2 as $key => $value) {
            if (isset($result[$key]) and is_array($result[$key]) and is_array($value)) {
                $result[$key] = static::mergeNatural($result[$key], $value);
            } elseif ( ( ! isset($result[$key]) or ( ! is_null($value)))) {
                $result[$key] = $value;
            }
        }
        return $result;
    }
public static function mergeNatural(array $array1, array $array2)
    {
        if (empty($array1)) {
            return $array2;
        }
        $result = $array1;
        foreach ($array2 as $key => $value) {
            if (isset($result[$key]) and is_array($result[$key]) and is_array($value)) {
                $result[$key] = static::mergeNatural($result[$key], $value);
            } elseif ( ( ! isset($result[$key]) or ( ! is_null($value)))) {
                $result[$key] = $value;
            }
        }
        return $result;
    }
public static function mergeNatural ( array $ array1 , array $ array2 ) { if ( empty ( $ array1 ) ) { return $ array2 ; } $ result = $ array1 ; foreach ( $ array2 as $ key => $ value ) { if ( isset ( $ result [ $ key ] ) and is_array ( $ result [ $ key ] ) and is_array ( $ value ) ) { $ result [ $ key ] = static :: mergeNatural ( $ result [ $ key ] , $ value ) ; } elseif ( ( ! isset ( $ result [ $ key ] ) or ( ! is_null ( $ value ) ) ) ) { $ result [ $ key ] = $ value ; } } return $ result ; }
Merges two arrays recursive "naturally"
Second array values takes precedence, with exception that its value on particular place is null
@param array $array1
@param array $array2
@return array
Merges two arrays recursive naturally Second array values takes precedence with exception that its value on particular place is null