Perform a merge on the given two arrays.
Deep merge will merge the two arrays in full depth.

@param array $array1
@param array $array2
@param bool  $deep

@return array
500060
public static function merge(array $array1, array $array2, $deep = false)
    {
        // Normal array merge
        if (!$deep) {
            return array_merge($array1, $array2);
        }

        // Perform a deep merge
        $merged = $array1;

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
                $merged[$key] = static::merge($merged[$key], $value, $deep);
            } else if (is_numeric($key)) {
                if (!in_array($value, $merged)) {
                    $merged[] = $value;
                }
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
1100135
public static function array_diff_multi($array1, $array2)
    {

        $res = array();
        foreach ($array1 as $entry) {
            if (!in_array($entry, $array2)) {
                $res[] = $entry;
            }
        }

        return $res;
    }
903055
public static function haveSameValues($array1, $array2)
    {
        return self::hasAllValues($array1, $array2) && self::hasAllValues($array2, $array1) ? true : false;
    }
514589
private static function configArrayMergeRecursive($array1, $array2) {
        if (is_array($array1) && is_array($array2)) {
            foreach ($array2 as $key => $value) {
                if (isset($array1[$key])) {
                    $array1[$key] = self::configArrayMergeRecursive($array1[$key], $array2[$key]);
                } else {
                    $array1[$key] = $value;
                }
            }
        } else {
            $array1 = $array2;
        }
        return $array1;
    }
873710
function mergeDeepArrays(array1, array2) {
  const length = Math.max(array1.length, array2.length);

  let index = -1,
      mergedArray = [];

  while (++index < length) {
    if (index < array2.length) {
      mergedArray[index] = getDeeplyMergedValues(array1[index], array2[index]);

      continue;
    }

    mergedArray[index] = array1[index];
  }

  return mergedArray;
}
1163474
public static function merge($array1, $array2)
	{
		$result = [];
		for ($i = 0; $i < func_num_args(); $i++) {
			$result = parent::merge($result, static::asArray(func_get_arg($i)));
		}

		return $result;
	}
1297967
protected static function _ArrayObjectMerge (\ArrayObject $array_object, $arrays) {
		$array1 = $array_object->getArrayCopy();
		foreach ($arrays as $array) {
			if (is_array($array)) {
				$array2 = $array;
			} else if ($array instanceof \ArrayObject) {
				$array2 = $array->getArrayCopy();
			} else {
				$array2 = (array) $array;
			}
			$array1 = array_merge($array1, $array2);
		}
		$array_object->exchangeArray($array1);
		return $array_object;
	}
996995
public function mergeArrays(array $array1, array $array2)
    {
        $allKeysNumeric = true;

        $config1Keys = array_keys($array1);
        $config2Keys = array_keys($array2);

        foreach ($config1Keys as $configKey) {
            if ( ! is_numeric($configKey)) {
                $allKeysNumeric = false;
                break;
            }
        }

        if ($allKeysNumeric) {
            foreach ($config2Keys as $configKey) {
                if ( ! is_numeric($configKey)) {
                    $allKeysNumeric = false;
                    break;
                }
            }
        }

        if ($allKeysNumeric) {
            return array_merge($array1, $array2);
        }

        $combined = [];

        foreach ($array1 as $key1 => $value1) {
            $value2 = array_key_exists($key1, $array2) !== false ? $array2[ $key1 ] : null;

            if (is_null($value2) || ( ! is_scalar($value1) && ! is_array($value1)) ||
                ( ! is_scalar($value2) && ! is_array($value2))) {
                $combined[ $key1 ] = $value1;

                continue;
            }

            if (is_scalar($value1) || is_null($value1)) {
                if (is_array($value2)) {
                    $combined[ $key1 ] = $this->mergeArrays([$value1], $value2);
                } else {
                    $combined[ $key1 ] = $value2;
                }

                continue;
            }

            if (is_array($value1)) {
                if (is_scalar($value2)) {
                    $combined[ $key1 ] = $value1;
                    $combined[ $key1 ][] = $value2;

                    continue;
                }

                if (is_array($value2)) {
                    $combined[ $key1 ] = $this->mergeArrays($value1, $value2);

                    continue;
                }
            }
        }

        foreach ($array2 as $key2 => $value2) {
            if ( ! is_numeric($key2) && ! array_key_exists($key2, $combined) !== false) {
                if (preg_match('/(.*)\+$/', $key2, $matches)) {
                    $key2 = array_key_exists(1, $matches) ? $matches[ 1 ] : null;

                    if (array_key_exists($key2, $combined) !== false) {
                        $combinedValue = $combined[ $key2 ];

                        if ( ! is_array($combinedValue)) {
                            $combined[ $key2 ] = [$combinedValue];
                        }

                        $combined[ $key2 ][] = $value2;
                    } else {
                        $combined[ $key2 ] = $value2;
                    }
                } else if (preg_match('/(.*)\-$/', $key2, $matches)) {
                    $key2 = array_key_exists(1, $matches) ? $matches[ 1 ] : null;

                    if (array_key_exists($key2, $combined) !== false) {
                        $combinedValue = $combined[ $key2 ];

                        if (is_array($combinedValue)) {
                            foreach ($combinedValue as $combinedValueKey => $combinedValueValue) {
                                if ($combinedValueValue === $value2) {
                                    unset($combinedValue[ $combinedValueKey ]);
                                }
                            }

                            $combined[ $key2 ] = $combinedValue;
                        } else {
                            if ($combinedValue === $value2) {
                                unset($combined[ $key2 ]);
                            }
                        }
                    }
                } else {
                    $combined[ $key2 ] = $value2;
                }
            }
        }

        return $combined;
    }
279211
private function _mergeDependencyVersions(array $array1, array $array2) {
        foreach ($array2 as $package => $version) {
            if (!isset($array1[$package])) {
                $array1[$package] = $version;
            } else {
                if ($array1[$package] != $version) {
                    $array1[$package] .= " ".$version;
                }
            }
        }
        return $array1;
    }
683405
function array_merge_recursive_unique($array1, $array2)
	{
		$arrays = func_get_args();
		$narrays = count($arrays);
		$ret = $arrays[0];
		for ($i = 1; $i < $narrays; $i ++) {
			foreach ($arrays[$i] as $key => $value) {
				if (((string) $key) === ((string)((int) $key))) { // integer or string as integer key - append
					$ret[] = $value;
				} else { // string key - merge
					if (is_array($value) && isset($ret[$key])) {
						$ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
					} else {
						$ret[$key] = $value;
					}
				}
			}
		}
		return $ret;
	}
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;
    }
1101103
public static function merge(array $source1, array $source2): array
    {
        $return = $source2;

        foreach ($source1 as $key => $value) {
            if ($value && is_array($value) && isset($source2[$key]) && is_array($source2[$key])) {
                $value = array_replace_recursive($source2[$key], $value);
            }
            $return[$key] = $value;
        }

        return $return;
    }
202261
protected function appendLines(array $array1 = [], array $array2 = [])
    {
        if (empty($array2)) {
            return $array1;
        }
        foreach ($array2 as $value) {
            $array1[] = $value;
        }

        return $array1;
    }
197398
public static function mergeTree(array $arr1, array $arr2): array
	{
		$res = $arr1 + $arr2;
		foreach (array_intersect_key($arr1, $arr2) as $k => $v) {
			if (is_array($v) && is_array($arr2[$k])) {
				$res[$k] = self::mergeTree($v, $arr2[$k]);
			}
		}
		return $res;
	}
405321
protected function mergeData(array $a, array $b)
    {
        if (isset($b['services']) === false) {
            return $b + $a;
        }

        return parent::mergeData($a, $b);
    }
1223825
public static function Merge(array $array1 = null, array $array2 = null){

		//check for the existance of the implementation class
		self::setImplmentationClass();

		//set the input parameters in a try...catch block for better error handling
		try {

			//set the value fo the $inputArray1 parameter
			$array1 = ( ! is_null($array1)) ? $array1 : self::$ArrayHelperClassInstance->getOutputElement();
			
			//set the value fo the $inputArray2 parameter
			$array2 = ( ! is_null($array2)) ? $array2 : self::$ArrayHelperClassInstance->getOutputElement();

			//check if null was supplied for the $key parameter
			if($array === null) throw new ArrayHelperException("NULL \$array1 value passed to ArrayHelper::Merge() method which merges the elements of two arrays. A valid array1 is expected!", 1);

			//check if null value was set for the inputArray paramter
			if($array2 === null) throw new ArrayHelperException("NULL \$array2 value passed to ArrayHelper::Merge() method which merges the elements of two arrays. A valid array2 is expected!", 1);
			
			//call the implementation class to merge the input array
			self::$ArrayHelperClassInstance->Merge($array1, $array2);

			//return the static instance
			return new static;

		} 

		//catch the error messages here
		catch (ArrayHelperException $ArrayHelperExceptionInstance) {

			//diplay the error message
			$ArrayHelperExceptionInstance->errorShow();
			
		}
	}
523009
public static function array_prepend( $array, $string, $deep = false )
    {
        if ( empty( $array ) || empty( $string ) )
        {
            return $array;
        }

        foreach ( $array as $key => $element )
        {
            if ( is_array( $element ) )
            {
                if ( $deep )
                {
                    $array[$key] = self::array_prepend( $element, $string, $deep );
                }
                else
                {
                    trigger_error( 'array_prepend: array element', E_USER_WARNING );
                }
            }
            else
            {
                $array[$key] = $string . $element;
            }
        }

        return $array;
    }