Map subtract against multiple arrays

[x₁ - y₁, x₂ - y₂, ... ]

@param array ...$arrays Two or more arrays of numbers

@return array

@throws Exception\BadDataException
506480
public static function subtract(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $differences      = array_map(
            function ($x) {
                return $x;
            },
            $arrays[0]
        );

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 1; $j < $number_of_arrays; $j++) {
                $differences[$i] -= $arrays[$j][$i];
            }
        }

        return $differences;
    }
1117615
private function arrayMergeRecursive(array ...$arrays)
    {
        $base = array_shift($arrays);
        if ( ! is_array($base)) {
            $base = empty($base) ? [] : [$base];
        }

        foreach ($arrays as $append) {
            if ( ! is_array($append)) {
                $append = [$append];
            }
            foreach ($append as $key => $value) {
                if ( ! array_key_exists($key, $base) && ! is_numeric($key)) {
                    $base[$key] = $append[$key];
                    continue;
                }

                if ((is_array($value) || (isset($base[$key]) && is_array($base[$key]))) && $this->isAssoc($value)) {
                    $base[$key] = $this->arrayMergeRecursive(
                        (array) $base[$key],
                        (array) $append[$key]
                    );
                } else {
                    if (is_numeric($key)) {
                        if ( ! in_array($value, $base)) {
                            $base[] = $value;
                        }
                    } else {
                        $base[$key] = $value;
                    }
                }
            }
        }

        return $base;
    }
131361
public static function reciprocal(array $xs): array
    {
        $zeros = array_filter(
            $xs,
            function (float $x) {
                return $x == 0;
            }
        );
        if (!empty($zeros)) {
            throw new Exception\BadDataException('Cannot compute the reciprocal of 0');
        }

        return array_map(
            function ($x) {
                return 1 / $x;
            },
            $xs
        );
    }
85012
public static function crossJoin(...$arrays)
    {
        $results = [[]];

        foreach ($arrays as $index => $array) {
            $append = [];

            foreach ($results as $product) {
                foreach ($array as $item) {
                    $product[$index] = $item;

                    $append[] = $product;
                }
            }

            $results = $append;
        }

        return $results;
    }
600376
public static function max(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $maxes            = array_map(
            function ($x) {
                return $x;
            },
            $arrays[0]
        );

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 1; $j < $number_of_arrays; $j++) {
                $maxes[$i] = max($maxes[$i], $arrays[$j][$i]);
            }
        }

        return $maxes;
    }
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;
    }
1035574
public static function typeCast(array $array)
    {
        $return = [];
        
        foreach ($array as $k => $v) {
            if (is_numeric($v)) {
                $return[$k] = StringHelper::typeCastNumeric($v);
            } elseif (is_array($v)) {
                $return[$k] = self::typeCast($v);
            } else {
                $return[$k] = $v;
            }
        }
        
        return $return;
    }
390893
public static function arrayDiffMultidimensional($array1, $array2)
    {
        $result = array();
        foreach ($array1 as $key => $value) {
            if (!is_array($array2) || !array_key_exists($key, $array2)) {
                $result[$key] = $value;
                continue;
            }
            if (is_array($value)) {
                $recursiveArrayDiff = static::ArrayDiffMultidimensional($value, $array2[$key]);
                if (count($recursiveArrayDiff)) {
                    $result[$key] = $recursiveArrayDiff;
                }
                continue;
            }
            if ($value != $array2[$key]) {
                $result[$key] = $value;
            }
        }

        return $result;
    }
971878
public function transpose($array)
    {
        $return = [];

        if (count($array)) {
            foreach ($array as $key => $values) {
                foreach ($values as $subkey => $value) {
                    $return[$subkey][$key] = $value;
                }
            }
        }

        return $return;
    }
1059742
public function toMappedArray(array $array)
    {
        $mappedArray = [];
        foreach ($this->getMapper() as $from => $to) {
            $mappedArray[$to] = $array[$from];
        }
        return $mappedArray;
    }
638989
public static function SetLowest (array $array, $keys, $value) {
		$keys = (array) $keys;
		if (empty($array)) {
			$tmp =& $array;
		} else {
			if (is_array($array)) {
				$tmp =& $array[array_shift($keys)];
			} else if ($tmp instanceof \ickx\fw2\vartype\arrays\LazyArrayObject) {
				$tmp =& $array->{array_shift($keys)};
			}
		}

		foreach ($keys as $key) {
			$tmp = (array) $tmp;
			if (!isset($tmp[$key])) {
				$tmp[$key] = null;
			}
			$tmp =& $tmp[$key];
		}

		$tmp = $value;
		unset($tmp);

		return $array;
	}
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;
    }
215686
protected function _flattenMultiDimensionalParams($arrays, $prefix = null)
    {
        $new = array();

        if (is_object($arrays)) {
            $arrays = get_object_vars($arrays);
        }

        foreach ($arrays as $key => $value) {
            $k =
                isset($prefix) ?
                    $prefix . '[' . $key . ']' :
                    $key;

            if (is_array($value) || is_object($value)) {
                $new =
                    array_merge(
                        $new,
                        $this->_flattenMultiDimensionalParams($value, $k)
                    );
            } else {
                $new[$k] = $value;
            }
        }

        return $new;
    }
158640
static public function fromArrays(array $keys, array $values) {
    if (count($keys) !== count($values)) {
      throw new SimpleOrderedMapException(
        'Length of keys and values does not match');
    }
    $map = new SimpleOrderedMap();
    $map->keys = array_values($keys);
    $map->values = array_values($values);
    return $map;
  }
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;
    }
1292205
public function reverseTransform($array)
    {
        if (null === $array) {
            return [];
        }

        if (!\is_array($array)) {
            throw new TransformationFailedException('Expected an array.');
        }

        $choices = $this->choiceList->getChoicesForValues($array);

        if (\count($choices) !== \count($array)) {
            throw new TransformationFailedException('Could not find all matching choices for the given values');
        }

        return $choices;
    }
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;
    }