Returns the sum of all values in the array (5+15+25):
<?php$a=array(5,15,25);echo array_sum($a);?>The array_sum() function returns the sum of all values in an array.
array_sum( array )
parameter | describe |
---|---|
array | Required. Specifies an array. |
Return value: | Returns the sum of all values in the array. |
---|---|
PHP version: | 4.0.4+ |
Update log: | Versions of PHP prior to 4.2.1 modified the passed array itself, converting the string values in it to numeric values (in most cases to zero, depending on the value). |
Returns the sum of all values in the array (52.2+13.7+0.9):
<?php$a=array("a"=>52.2,"b"=>13.7,"c"=>0.9);echo array_sum($a);?>