Automattic\WooCommerce\Vendor\GraphQL\Type\Definition

QueryPlan::arrayMergeDeepprivateWC 1.0

Merges nested arrays, but handles non array values differently from array_merge_recursive. While array_merge_recursive tries to merge non-array values, in this implementation they will be overwritten.

Method of the class: QueryPlan{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->arrayMergeDeep( $array1, $array2 ): array;
$array1(array) (required)
.
$array2(array) (required)
.

Notes

QueryPlan::arrayMergeDeep() code WC 10.9.1

private function arrayMergeDeep(array $array1, array $array2): array
{
    foreach ($array2 as $key => &$value) {
        if (is_numeric($key)) {
            if (! in_array($value, $array1, true)) {
                $array1[] = $value;
            }
        } elseif (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
            $array1[$key] = $this->arrayMergeDeep($array1[$key], $value);
        } else {
            $array1[$key] = $value;
        }
    }

    return $array1;
}