src/Arr.php
public static function replaceExisting(array $array1, array $array2, bool $recursive = false): array
    {
        foreach ($array1 as $key => $value) {
            if (array_key_exists($key, $array2)) {
                $value2 = $array2[$key];
                if ($recursive && is_array($value)) {
                    $value2 = self::replaceExisting($value, $value2, $recursive);
                }
                $array1[$key] = $value2;
            }
        }

        return $array1;
    }
public static function replaceExisting(array $array1, array $array2, bool $recursive = false): array
    {
        foreach ($array1 as $key => $value) {
            if (array_key_exists($key, $array2)) {
                $value2 = $array2[$key];
                if ($recursive && is_array($value)) {
                    $value2 = self::replaceExisting($value, $value2, $recursive);
                }
                $array1[$key] = $value2;
            }
        }

        return $array1;
    }
public static function replaceExisting ( array $ array1 , array $ array2 , bool $ recursive = false ) : array { foreach ( $ array1 as $ key => $ value ) { if ( array_key_exists ( $ key , $ array2 ) ) { $ value2 = $ array2 [ $ key ] ; if ( $ recursive && is_array ( $ value ) ) { $ value2 = self :: replaceExisting ( $ value , $ value2 , $ recursive ) ; } $ array1 [ $ key ] = $ value2 ; } } return $ array1 ; }
Replaces values in array1 with values from array2 comparing keys and
discarding keys that doesn't exist in array1.

@param array $array1
@param array $array2
@param bool  $recursive
@return array
Replaces values in array1 with values from array2 comparing keys and discarding keys that doesn t exist in array1 .