Merge arrays to one

@param array ...$arrays
@return array|null
198731
protected function mergeResourceArrays(...$arrays) : ?array
    {
        $merged = [];

        foreach ($arrays as $array) {
            if (!is_array($array)) {
                continue;
            }

            /** @var ResourceSettings $resource */
            foreach ($array as $resource) {
                $this->mergeWithOrder($resource, $merged);
            }
        }

        return !empty($merged) ? $merged : null;
    }
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;
    }
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;
    }
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;
    }
143429
protected function flatten($array)
    {
        return array_reduce($array, function ($result, $item) {
            if (! is_array($item)) {
                return array_merge($result, [$item]);
            }

            return array_merge($result, $this->flatten($item));
        }, []);
    }
1092950
public static function arrayMergeRecursiveUnique($array1, $array2)
    {
        if (empty($array1)) {
            // Optimize the base case
            return $array2;
        }

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
                $value = static::arrayMergeRecursiveUnique($array1[$key], $value);
            }
            $array1[$key] = $value;
        }

        return $array1;
    }
679579
public function mergeRecursive($array)
    {
        if ($this->isInstanceOf($array, $this)) {
            $array = $array->val();
        }

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

        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;
    }
1100568
public static function flatten($array)
    {
        $return = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $return = \array_merge($return, static::flatten($value));
            } elseif ($value instanceof Collection) {
                $return = \array_merge($return, static::flatten($value->all()));
            } else {
                $return[$key] = $value;
            }
        }

        return $return;
    }
562094
private function mergeArrays($deep, $array1, $array2)
    {
        if ($deep === 'merge') {
            return Utils::arrayMergeRecursiveUnique($array1, $array2);
        }
        if ($deep === true) {
            return array_replace_recursive($array1, $array2);
        }

        return array_merge($array1, $array2);
    }
858403
public static function multiply(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $products         = array_fill(0, $length_of_arrays, 1);

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 0; $j < $number_of_arrays; $j++) {
                $products[$i] *= $arrays[$j][$i];
            }
        }

        return $products;
    }
293126
public static function keyFlattening($array, $keys = []) {
		if (is_array($array)) {
			$result = [];
			foreach ($array as $key => $value) {
				$tmp_keys = $keys;
				$tmp_keys [] = $key;
				$result = array_merge($result, static::keyFlattening($value,$tmp_keys));
			}
			return $result;
		}

		$key = array_shift($keys);
		return [
			empty($keys) ? $key : sprintf('%s[%s]', $key, implode ('][', $keys)) => $array,
		];
	}
337076
public static function array_flatten(array $array){
		$index = 0;
		$count = count($array);

		while ($index < $count) {
			if (is_array($array[$index])) {
				array_splice($array, $index, 1, $array[$index]);
			} else {
				++$index;
			}
			$count = count($array);
		}
		return $array;
	}
827446
public static function recursiveMerge($array1, $array2) {

        if ($array1 instanceof AssociativeArray) {
            $array1 = $array1->toArray();
        }

        if ($array2 instanceof AssociativeArray) {
            $array2 = $array2->toArray();
        }

        if (ArrayUtils::isAssociative($array1) != ArrayUtils::isAssociative($array2)) {

            if (ArrayUtils::isAssociative($array1)) {
                $array1 = array($array1);
            } else {
                $array2 = array($array2);
            }
        }

        $combinedKeys = array_unique(array_merge(array_keys($array1), array_keys($array2)));

        $mergedArray = array();
        foreach ($combinedKeys as $key) {


            if (isset($array1[$key]) && isset($array2[$key])) {

                if ((is_array($array1[$key]) || $array1[$key] instanceof AssociativeArray) && (is_array($array2[$key]) || $array2[$key] instanceof AssociativeArray)) {
                    $mergedArray[$key] = ArrayUtils::recursiveMerge($array1[$key], $array2[$key]);
                } else {
                    $mergedArray[$key] = $array1[$key];
                }

            } else {
                $mergedArray[$key] = isset($array1[$key]) ? $array1[$key] : $array2[$key];
            }

        }


        return $mergedArray;
    }
803902
public static function deepMergePropertiesArray($arrays)
    {
        $result = array();

        foreach ($arrays as $array) {
            foreach ($array as $key => $value) {
                // Renumber integer keys as array_merge_recursive() does. Note that PHP
                // automatically converts array keys that are integer strings (e.g., '1')
                // to integers.
                if (is_integer($key)) {
                    $result[] = $value;
                } // Recurse when both values are arrays.
                elseif (isset($result [$key]) && is_array($result [$key]) && is_array($value)) {
                    $result[$key] = self::deepMergePropertiesArray(array($result [$key], $value));
                } // Otherwise, use the latter value, overriding any previous value.
                else {
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }
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;
    }
1164492
public function arrayCopy(array $array)
    {
        $copy = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $copy[ $key ] = $this->arrayCopy($value);
            } elseif (is_object($value)) {
                $copy[ $key ] = clone $value;
            } else {
                $copy[ $key ] = $value;
            }
        }

        return $copy;
    }