private static function mergeArraysRecursively($firstArray, $secondArray, $parentKeys)
    {
        $result = $firstArray;

        foreach ($secondArray as $key => $value) {
            if (array_key_exists($key, $firstArray)) {
                array_push($parentKeys, $key);
                $result[$key] = self::mergeTwoValues($firstArray[$key], $value, $parentKeys);
                array_pop($parentKeys);
            }
            else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
private static function mergeArraysRecursively($firstArray, $secondArray, $parentKeys)
    {
        $result = $firstArray;

        foreach ($secondArray as $key => $value) {
            if (array_key_exists($key, $firstArray)) {
                array_push($parentKeys, $key);
                $result[$key] = self::mergeTwoValues($firstArray[$key], $value, $parentKeys);
                array_pop($parentKeys);
            }
            else {
                $result[$key] = $value;
            }
        }

        return $result;
    }
private static function mergeArraysRecursively ( $ firstArray , $ secondArray , $ parentKeys ) { $ result = $ firstArray ; foreach ( $ secondArray as $ key => $ value ) { if ( array_key_exists ( $ key , $ firstArray ) ) { array_push ( $ parentKeys , $ key ) ; $ result [ $ key ] = self :: mergeTwoValues ( $ firstArray [ $ key ] , $ value , $ parentKeys ) ; array_pop ( $ parentKeys ) ; } else { $ result [ $ key ] = $ value ; } } return $ result ; }
Merge arrays recursively.

This merges the values when they are arrays, and overrides the value in
the first array with the second otherwise.

This is used instead of array_merge_recursive since that will turn
duplicated non-array values into arrays.

@throws \Best\DotNotation\InconsistentKeyTypes if a key that already exists is changed to an
array, or if an array is changed to a string.

@param  array $firstArray First array to merge.
@param  array $secondArray Second array to merge.
@param  array $parentKeys Key path to parents used for error reporting.

@return array The merged array.
Merge arrays recursively .