public static function sum($items, $callback = null)
    {
        $callback = static::valueRetriever($callback);
        $sum = null;

        foreach ($items as $item) {
            if (($amount = $callback($item)) !== null) {
                $sum = $sum ? $sum->add($amount) : $amount;
            }
        }

        return $sum ?: static::zero();
    }
public static function sum($items, $callback = null)
    {
        $callback = static::valueRetriever($callback);
        $sum = null;

        foreach ($items as $item) {
            if (($amount = $callback($item)) !== null) {
                $sum = $sum ? $sum->add($amount) : $amount;
            }
        }

        return $sum ?: static::zero();
    }
public static function sum ( $ items , $ callback = null ) { $ callback = static :: valueRetriever ( $ callback ) ; $ sum = null ; foreach ( $ items as $ item ) { if ( ( $ amount = $ callback ( $ item ) ) !== null ) { $ sum = $ sum ? $ sum -> add ( $ amount ) : $ amount ; } } return $ sum ? : static :: zero ( ) ; }
Retrieve the sum of an array.

@param $items
@param null $callback

@return Amount

@throws \Exception
Retrieve the sum of an array .