src/Collection/ArrayCollection.php
public function reduce(callable $callback, $initial = null)
    {
        $accumulator = $initial;

        foreach ($this->items as $key => $value) {
            $accumulator = $callback($accumulator, $value, $key);
        }

        return $accumulator;
    }
public function reduce(callable $callback, $initial = null)
    {
        $accumulator = $initial;

        foreach ($this->items as $key => $value) {
            $accumulator = $callback($accumulator, $value, $key);
        }

        return $accumulator;
    }
public function reduce ( callable $ callback , $ initial = null ) { $ accumulator = $ initial ; foreach ( $ this -> items as $ key => $ value ) { $ accumulator = $ callback ( $ accumulator , $ value , $ key ) ; } return $ accumulator ; }
Reduces the collection to a single value

The callback must return the accumulator.

Callback signature:

<code>
function ($accumulator, $value, $key): mixed {}
</code>

@param callable $callback The callback function
@param mixed    $initial  The initial value

@return mixed
Reduces the collection to a single value