src/ConfigCollectionFactory.php
private static function arrayMergeRecursiveDistinct(array $merged, array $other): array
    {
        foreach ($other as $key => $value) {
            if (is_array($value) && is_array($merged[$key] ?? [])) {
                $merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key] ?? [], $value);
            } elseif (is_int($key)) {
                // Avoid arrays being overridden.
                $merged = array_unique(
                    array_merge($merged, [$value])
                );
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
private static function arrayMergeRecursiveDistinct(array $merged, array $other): array
    {
        foreach ($other as $key => $value) {
            if (is_array($value) && is_array($merged[$key] ?? [])) {
                $merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key] ?? [], $value);
            } elseif (is_int($key)) {
                // Avoid arrays being overridden.
                $merged = array_unique(
                    array_merge($merged, [$value])
                );
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
private static function arrayMergeRecursiveDistinct ( array $ merged , array $ other ) : array { foreach ( $ other as $ key => $ value ) { if ( is_array ( $ value ) && is_array ( $ merged [ $ key ] ?? [ ] ) ) { $ merged [ $ key ] = self :: arrayMergeRecursiveDistinct ( $ merged [ $ key ] ?? [ ] , $ value ) ; } elseif ( is_int ( $ key ) ) { // Avoid arrays being overridden. $ merged = array_unique ( array_merge ( $ merged , [ $ value ] ) ) ; } else { $ merged [ $ key ] = $ value ; } } return $ merged ; }
This does not change the data types of the values in the arrays. Matching keys' values in the second array
overwrite those in the first array, as is the case with array_merge.

This is modified from an example on php.net.

@see https://secure.php.net/manual/en/function.array-merge-recursive.php#92195

@param array $merged The first array.
@param array $other  The second array.

@return array
This does not change the data types of the values in the arrays . Matching keys values in the second array overwrite those in the first array as is the case with array_merge .