Php Array Elements Sum Function

What is array_sum Function?

Explanation

The "array_sum" function is used calculate the sum of element values in an array.

Syntax:


array_sum(array)

In the above syntax "array" specifies the array, for which to calculate the sum of values.

Example :


<?php
$a=array(0=>"10",1=>"20",2=>"30");
print_r(array_sum($a));
?>
Result :

60

In the above example the function calculates the sum of the array "$a" values, returns the sum as 60.

PHP Topics


Ask Questions

Ask Question