Home >Backend Development >PHP Problem >How to use php array_sum function
php array_sum function is used to calculate the sum of all values in the returned array. Its syntax is array_sum(arra). The parameter array is required and refers to the specified array.
#php array_sum function how to use?
Function: Returns the sum of all values in the array.
Syntax:
array_sum(arra)
Parameters:
array Required. Specifies an array.
Description:
If all values are integers, return an integer value. If one or more of the values is a floating point number, a floating point number is returned.
php array_sum() function usage example 1
d1dc34bb876fd024bf845d1c60b42b79199," Foundation"=>349,"Eyeshadow"=>99);
echo array_sum($a);
?>
Output:
647
php array_sum() function usage example 2
<?php $arr = array('蚂蚁花呗要还' => 578,'蚂蚁借呗要还' => 1500, '网上银行要还' => 2000); echo "那么你这个月要还".array_sum($arr); ?>
Output:
那么你这个月要还4078
The above is the detailed content of How to use php array_sum function. For more information, please follow other related articles on the PHP Chinese website!