Merge two arrays.
@param array first array
@param array second array
@return array the two arrays combined into one
Thanks to Wojtazzz on stackoverflow, http://stackoverflow.com/questions/20550442/merging-arrays-and-overwriting-value-when-keys-are-equal
161856
private static function merge($array1, $array2) {

        foreach (array_keys($array2) as $key) {
            if (isset($array1[$key])) {
                unset($array1[$key]);
            }
        }
        return $array1 + $array2;
    }
738803
public static byte[] join(List<byte[]> arrays) {
    int maxlength = 0;
    for (byte[] array : arrays) {
      maxlength += array.length;
    }
    byte[] rs = new byte[maxlength];
    int pos = 0;
    for (byte[] array : arrays) {
      System.arraycopy(array, 0, rs, pos, array.length);
      pos += array.length;
    }
    return rs;
  }
1364926
protected function mergeArrays()
    {
        $arrays = func_get_args();
        $merged = array();

        foreach ($arrays as $array) {
            foreach ($array as $key => $value) {
                $merged = $this->setValue($key, $value, $merged);
            }
        }

        return $merged;
    }
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;
    }
295607
static function arrayMerge($array1, $array2, $overwriteValue = true)
    {
//        if($overwriteValue) {
//            foreach ($array2 as $key => $Value) {
//                if (array_key_exists($key, $array1) && is_array($Value)) {
//                    $array1[$key] = self::arrayMergeRecursively(
//                        $array1[$key], $array2[$key], $overwriteValue
//                    );
//                } else {
//                    $array1[$key] = $Value;
//                }
//            }
//        } else {
//            $array1 = array_merge_recursive($array1, $array2);
//        }

        $arrayMerged = array_merge_recursive($array1, $array2);
        $arrayUnique = array_unique($arrayMerged, SORT_STRING);

        return $arrayUnique;
    }
1230029
public function merge($array)
    {
        if ($this->isInstanceOf($array, $this)) {
            $array = $array->val();
        }

        $this->val(array_merge($this->val(), $array));

        return $this;
    }
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;
	}
583796
public static function multiToAssoc(array $arrays)
    {
        $results = [];
        foreach ($arrays as $key => $value) {
            if (self::isReallyArray($value) === true) {
                $results = array_merge($results, self::multiToAssoc($value));
            } else {
                $results[$key] = $value;
            }
        }

        return $results;
    }
377506
public static function array_merge_deep(array $array1, array $array2)
	{
		$merged = $array1;

		foreach ($array2 as $key => $value) {
			if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
				$merged[$key] = self::array_merge_deep($merged[$key], $value);
			} elseif (is_numeric($key)) {
				// Numeric key. Look at values instead of keys to determine if it already exists.
				if (!in_array($value, $merged)) {
					$merged[] = $value;
				}
			} else {
				$merged[$key] = $value;
			}

		}

		return $merged;
	}
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;
    }
1058629
public static function mergeRecursiveDistinct(array &$array1, array &$array2)
    {
        Deprecated::method(3.3, 'Use array_replace_recursive() or Arr::replaceRecursive() instead.');

        $merged = $array1;

        foreach ($array2 as $key => &$value) {
            // if $key = 'accept_file_types, don't merge.
            if ($key == 'accept_file_types') {
                $merged[$key] = $array2[$key];
                continue;
            }

            if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
                $merged[$key] = static::mergeRecursiveDistinct($merged[$key], $value);
            } else {
                $merged[$key] = $value;
            }
        }

        return $merged;
    }
231165
function mergeArrays(array1, array2) {
  return array2.length >= array1.length ? [...array2] : [...array2, ...array1.slice(array2.length)];
}
63680
protected function deep_merge_recursive($arrays)
    {
        $result = array();

        foreach ($arrays as $array)
        {
            foreach ($array as $key => $value)
            {
                if (is_integer($key))
                {
                    $result[] = $value;
                }
                elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value))
                {
                    $result[$key] = $this->deep_merge_recursive(array($result[$key], $value));
                }
                // handle embeded object with object value
                elseif (isset($result[$key]) && is_object($result[$key]) && is_object($value))
                {
                    $result[$key] = (object)$this->deep_merge_recursive(array((array)$result[$key], (array)$value));
                }
                // handle embeded object with array value
                elseif (isset($result[$key]) && is_object($result[$key]) && is_array($value))
                {
                    $result[$key] = (object)$this->deep_merge_recursive(array((array)$result[$key], $value));
                }
                else
                {
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }
788913
public static function mergeWithout(array $first, array $second, array $keys)
    {
        $result = array_merge($first, $second);
        return self::arrayWithout($result, $keys);
    }
92474
public static function merge($array1, $array2, $recursive = false)
    {
        if (!self::isValid($array1) ||
            !self::isValid($array2)) {
            return false;
        }

        if ($recursive) {
            return array_merge_recursive($array1, $array2);
        } else {
            return array_merge($array1, $array2);
        }
    }
1353034
public static function recursiveMerge(...$arrays)
    {
        $merged = array ();
        foreach($arrays as $array)
        {
            if (!is_array($array))
            {
                continue;
            }
            foreach ( $array as $key => $value )
            {
                if (is_string ( $key ))
                {
                    if (is_array ( $value ) && isset($merged[$key]) && is_array ( $merged [$key] ))
                    {
                        $merged [$key] = static::recursiveMerge ( $merged [$key], $value );
                    }
                    else
                    {
                        $merged [$key] = $value;
                    }
                }
                else
                {
                    $merged [] = $value;
                }
            }
        }
        return $merged;
    }
665075
public static int[] Concatenate(int[] array, int[] array2) {
        int[] all = new int[array.length + array2.length];
        int idx = 0;

        //First array
        for (int i = 0; i < array.length; i++)
            all[idx++] = array[i];

        //Second array
        for (int i = 0; i < array2.length; i++)
            all[idx++] = array2[i];

        return all;
    }