Current Location: Home> Function Categories> array_sum

array_sum

Summarize all values ​​in an array
Name:array_sum
Category:Array
Programming Language:php
One-line Description:Returns the sum of values ​​in the array.

Definition and usage

array_sum() function returns the sum of all values ​​in the array.

If all values ​​are integers, an integer value is returned. If one or more of the values ​​are floating points, the floating point number is returned.

Example

Example 1

Returns the sum of all values ​​in the array (5+15+25):

 <?php
$a = array ( 5 , 15 , 25 ) ;
echo array_sum ( $a ) ;
?>

Try it yourself

Example 2

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 ) ;
?>

Try it yourself

grammar

 array_sum ( array )
parameter describe
array Required. Specify array.
Similar Functions
Popular Articles