merge recursive.

@access  public
@param   array   $array1
@param   array   $array2
424189
public function merge()
    {
        $marged = NULL;
        foreach (func_get_args() as $arg) {
            // first is override.
            if ($marged === null) {
                $marged = $arg;

            // when mismatch variable type, then override.
            } elseif (gettype($marged) !== gettype($arg)) {
                $marged = $arg;

            // when not array, then override.
            } elseif (! is_array($arg)) {
                $marged = $arg;

            // when both array, then merge recursive.
            } else {
                foreach ($arg as $_key => $_val) {
                    // when int key, then push.
                    if(is_int($_key)) {
                        $marged[] = $_val;
                    // when not exists key, then override.
                    } elseif(! isset($marged[$_key])) {
                        $marged[$_key] = $_val;
                    // merge.
                    } else {
                        $marged[$_key] = $this->merge($marged[$_key], $_val);
                    }
                }
            }
        }
        return $marged;
    }
102940
protected function hasIntersectArray(array $array1, array $array2)
    {
        foreach ($array1 as $value) {
            if (in_array($value, $array2)) {
                return true;
            }
        }

        return false;
    }
905919
protected static function arrayMerge($a, $b)
    {
        foreach ($b as $k => $v) {
            if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
                $a[$k] = $v;
            } else {
                $a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
            }
        }
        return $a;
    }
1336725
protected static function _merge($firstArray, $secondArray)
    {
        $merged = Hash::merge($firstArray, $secondArray);
        foreach ($merged as $key => $val) {
            if (is_array($val) && is_int(key($val))) {
                $merged[$key] = array_unique($val);
            }
        }
        return $merged;
    }
856840
private static function arrayDiffRecursive(array $array1, array $array2)
    {
        $finalArray = [];
        foreach ($array1 as $KeyArray1 => $ValueArray1) {
            if (array_key_exists($KeyArray1, $array2)) {
                if (is_array($ValueArray1)) {
                    $arrayDiffRecursive = self::arrayDiffRecursive($ValueArray1, $array2[$KeyArray1]);
                    if (count($arrayDiffRecursive)) {
                        $finalArray[$KeyArray1] = $arrayDiffRecursive;
                    }
                }
            } else {
                $finalArray[$KeyArray1] = $ValueArray1;
            }
        }

        return $finalArray;
    }
923887
public static function areRecursivelyEquals(array $array1, array $array2)
    {
        if (\count($array1) !== \count($array2)) {
            return false;
        }

        return self::arrayIsContained($array1, $array2);
    }
425667
public function merge(array $items, $recursive = false)
    {
        foreach ($items as $key => $value)
        {
            $this->set($key, $value);
        }

        return $this;
    }
903851
public function merge(array $a, array $b)
    {
        foreach ($b as $key => $value) {
            if (array_key_exists($key, $a)) {
                if (is_int($key)) {
                    $a[] = $value;
                } elseif (is_array($value) && is_array($a[$key])) {
                    $a[$key] = $this->merge($a[$key], $value);
                } else {
                    $a[$key] = $value;
                }
            } else {
                $a[$key] = $value;
            }
        }

        return $a;
    }
639691
public static function arrayDiff(array $array1, array $array2)
    {
        $diff = array();

        foreach ($array1 as $key1 => $value1) {
            if (array_key_exists($key1, $array2)) {
                if ($value1 !== $array2[$key1]) {
                    $diff[$key1] = $array2[$key1];
                }
                continue;
            }

            $diff[$key1] = $value1;
        }

        $diff = array_merge($diff, array_diff_key($array2, $array1));

        return $diff;
    }
1287407
private function my_merge($a, $b){
        if (is_array($b)) {
            foreach ($b as $k => $v) {
                if (isset($a[$k])) {
                    $a[$k] = $this->my_merge($a[$k], $v);
                }else{
                    $a[$k] = $v;
                }
            }
        }
        @asort($a);
        return $a;
    }
803476
public static function merge(array ...$arrays): array
    {
        $res = array_shift($arrays);
        while (!empty($arrays)) {
            foreach (array_shift($arrays) as $key => $value) {
                if (is_int($key)) {
                    if (array_key_exists($key, $res)) {
                        $res[] = $value;
                    } else {
                        $res[$key] = $value;
                    }
                } elseif (
                    is_array($value)
                    && isset($res[$key])
                    && is_array($res[$key])
                ) {
                    $res[$key] = static::merge($res[$key], $value);
                } else {
                    $res[$key] = $value;
                }
            }
        }
        return $res;
    }
384176
public static function merge_retain_recursive($array_a = array(), $array_b = array())
	{
		$array_merge = $array_a;

		if (empty($array_a) && empty($array_b))
		{
			return $array_merge;
		}

		foreach ($array_b as $field => $value)
		{
			if (! array_key_exists($field, $array_a))
			{
				$array_merge[$field] = $value;
				continue;
			}

			if (! empty($value))
			{
				if (is_array($array_merge[$field]) && is_array($value))
				{
					$array_merge[$field] = self::merge_retain_recursive($array_merge[$field], $value);
				}
				else
				{
					$array_merge[$field] = $value;
				}
			}
		}

		return $array_merge;
	}
853628
function merge(arrays, comp) {
		var mid,
			a1, i1,
			a2, i2,
			result;

		if (arrays.length === 1) {
			return arrays[0];
		} else if (arrays.length === 2) {
			// merge two arrays
			a1 = arrays[0];
			a2 = arrays[1];
			i1 = i2 = 0;
			result = [];
			while(i1 < a1.length && i2 < a2.length) {
				if (comp(a2[i2], a1[i1]) > 0) {
					result.push(a1[i1]);
					i1++;
				} else {
					result.push(a2[i2]);
					i2++;
				}
			}
			while(i1 < a1.length) {
				result.push(a1[i1]);
				i1++;
			}
			while(i2 < a2.length) {
				result.push(a2[i2]);
				i2++;
			}
			return result;
		} else {
			mid = Math.floor(arrays.length / 2);
			return merge([
				merge(arrays.slice(0, mid), comp),
				merge(arrays.slice(mid), comp)
			], comp);
		}

	}
231165
function mergeArrays(array1, array2) {
  return array2.length >= array1.length ? [...array2] : [...array2, ...array1.slice(array2.length)];
}
899096
protected function _arrayMergeRecursive($firstArray, $secondArray)
    {
        if (is_array($firstArray) && is_array($secondArray)) {
            foreach ($secondArray as $key => $value) {
                if (isset($firstArray[$key])) {
                    $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
                } else {
                    if($key === 0) {
                        $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
                    } else {
                        $firstArray[$key] = $value;
                    }
                }
            }
        } else {
            $firstArray = $secondArray;
        }

        return $firstArray;
    }
1204134
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;
    }
90894
public function merge( array ...$array_to_merge ) : self {

		foreach ( $array_to_merge as $arr ) {
			$items = array_replace_recursive( $this->getArrayCopy(), $arr );

			foreach ( $items as $key => $value ) {
				$this->offsetSet( $key, $value );
			}
		}

		return $this;
	}