src/Traits/Arrays.php
public static function patch(array $array, array $patches, string $parent = ''): array
    {
        foreach ($array as $key => $value) {
            $z = $parent . '/' . $key;

            if (isset($patches[$z])) {
                $array[$key] = $patches[$z];
                unset($patches[$z]);

                if (!count($patches)) {
                    break;
                }
            }

            if (is_array($value)) {
                $array[$key] = static::patch($value, $patches, $z);
            }
        }

        return $array;
    }
public static function patch(array $array, array $patches, string $parent = ''): array
    {
        foreach ($array as $key => $value) {
            $z = $parent . '/' . $key;

            if (isset($patches[$z])) {
                $array[$key] = $patches[$z];
                unset($patches[$z]);

                if (!count($patches)) {
                    break;
                }
            }

            if (is_array($value)) {
                $array[$key] = static::patch($value, $patches, $z);
            }
        }

        return $array;
    }
public static function patch ( array $ array , array $ patches , string $ parent = '' ) : array { foreach ( $ array as $ key => $ value ) { $ z = $ parent . '/' . $ key ; if ( isset ( $ patches [ $ z ] ) ) { $ array [ $ key ] = $ patches [ $ z ] ; unset ( $ patches [ $ z ] ) ; if ( ! count ( $ patches ) ) { break ; } } if ( is_array ( $ value ) ) { $ array [ $ key ] = static :: patch ( $ value , $ patches , $ z ) ; } } return $ array ; }
Patches array by xpath.

@usage __::patch(
['addr' => ['country' => 'US', 'zip' => 12345]],
['/addr/country' => 'CA','/addr/zip' => 54321]
);
*       >> ['addr' => ['country' => 'CA', 'zip' => 54321]]

@param array  $array   The array to patch
@param array  $patches List of new xpath-value pairs
@param string $parent

@return array Returns patched array
Patches array by xpath .