array_sum() function in php
0 2172
array_sum() function of PHP is used to retrieve the sum of all elements of a PHP array. It is an inbuilt function of PHP.
Syntax:
array_sum($array);
here,
$array is a PHP array.
Example 1:
<?php $arr1=array(1,2,3,4,5,6,7,8,9); $result=array_sum($arr1); echo "Sum is : ".$result; ?>
Output:
Example 2:
<?php $arr1=array("e1"=>25,"e2"=>50,"e3"=>75,"e4"=>15,"e5"=>35,"e6"=>1); $result=array_sum($arr1); echo "Sum is : ".$result; ?>
Output:
Share:
Comments
Waiting for your comments