The array_sum function calculates and returns the sum of all the values of the given array.
What is the syntax of the array_sum function in PHP?
array_sum(array)
Parameter | Details |
---|---|
array | The array to calculate the sum of – Required |
Examples of array_sum function
Example 1. Return sum of array values 2+7+15
<?php
$arr=array(2,7,15);
echo array_sum($arr);
?>
Example 2. Return sum of associative array values 2.1+7.2+15.3
<?php
$arr=array("a"=>2.1,"b"=>7.2,"c"=>15.3);
echo array_sum($arr);
?>