src/Collection/ArrayCollection.php
public function sum(?callable $callback = null)
    {
        if ($callback === null) {
            $callback = function ($value, $key) {
                return $value;
            };
        }

        return $this->reduce(function ($total, $value, $key) use ($callback) {
            return $total + $callback($value, $key);
        }, 0);
    }
public function sum(?callable $callback = null)
    {
        if ($callback === null) {
            $callback = function ($value, $key) {
                return $value;
            };
        }

        return $this->reduce(function ($total, $value, $key) use ($callback) {
            return $total + $callback($value, $key);
        }, 0);
    }
public function sum ( ? callable $ callback = null ) { if ( $ callback === null ) { $ callback = function ( $ value , $ key ) { return $ value ; } ; } return $ this -> reduce ( function ( $ total , $ value , $ key ) use ( $ callback ) { return $ total + $ callback ( $ value , $ key ) ; } , 0 ) ; }
Retrieves the sum of the collection

The callback should return a value to sum.

Callback signature:

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

@param callable|null $callback The callback function

@return mixed
Retrieves the sum of the collection