[PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8]
array_sum — Calculate the sum of values in an array
Description
array_sum[array $array
]: int|float
Parameters
array
The input array.
Return Values
Returns the sum of values as an integer or float; 0
if the array
is empty.
Examples
Example #1 array_sum[] examples
The above example will output:
rodrigo at adboosters dot com ¶
7 months ago
If you want to calculate the sum in multi-dimensional arrays:
Example:
samiulmomin191139 at gmail dot com ¶
7 months ago
444 ¶
6 months ago
$total = 0;
foreach [$array as $key => $value]{
$total += $value;
}
Print "sum $total";