public function reduce(array $array, callable $callback, $initialValue = null)
    {
        if ($initialValue !== null) {
            $accumulator = $initialValue;
        } else {
            $accumulator = array_shift($array);
        }
        foreach ($array as $key => $element) {
            $accumulator = $callback($accumulator, $element, $key);
        }
        return $accumulator;
    }
public function reduce(array $array, callable $callback, $initialValue = null)
    {
        if ($initialValue !== null) {
            $accumulator = $initialValue;
        } else {
            $accumulator = array_shift($array);
        }
        foreach ($array as $key => $element) {
            $accumulator = $callback($accumulator, $element, $key);
        }
        return $accumulator;
    }
public function reduce ( array $ array , callable $ callback , $ initialValue = null ) { if ( $ initialValue !== null ) { $ accumulator = $ initialValue ; } else { $ accumulator = array_shift ( $ array ) ; } foreach ( $ array as $ key => $ element ) { $ accumulator = $ callback ( $ accumulator , $ element , $ key ) ; } return $ accumulator ; }
Apply the callback to each element of the array and accumulate a single value

Examples::

Array.reduce([1, 2, 3, 4], (accumulator, currentValue) => accumulator + currentValue) // == 10
Array.reduce([1, 2, 3, 4], (accumulator, currentValue) => accumulator + currentValue, 1) // == 11

@param array $array Array of elements to reduce to a value
@param callable $callback Callback for accumulating values, accumulator, current value and key will be passed as arguments
@param mixed $initialValue Initial value, defaults to first item in array and callback starts with second entry
@return mixed
Apply the callback to each element of the array and accumulate a single value