array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'fr', ), 'this' => array ( 0 => 'ds-set.sum.php', 1 => 'Ds\\Set::sum', ), 'up' => array ( 0 => 'class.ds-set.php', 1 => 'Ds\\Set', ), 'prev' => array ( 0 => 'ds-set.sorted.php', 1 => 'Ds\\Set::sorted', ), 'next' => array ( 0 => 'ds-set.toarray.php', 1 => 'Ds\\Set::toArray', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ds/ds/set/sum.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL ds >= 1.0.0)
Ds\Set::sum — Returns the sum of all values in the set
Returns the sum of all values in the set.
Note:
Arrays and objects are considered equal to zero when calculating the sum.
Cette fonction ne contient aucun paramètre.
The sum of all the values in the set as either a float or int depending on the values in the set.
Exemple #1 Ds\Set::sum() integer example
<?php
$set = new \Ds\Set([1, 2, 3]);
var_dump($set->sum());
?>
Résultat de l'exemple ci-dessus est similaire à :
int(6)
Exemple #2 Ds\Set::sum() float example
<?php
$set = new \Ds\Set([1, 2.5, 3]);
var_dump($set->sum());
?>
Résultat de l'exemple ci-dessus est similaire à :
float(6.5)