array_sum — php array function to find the sum of the element of the array

The array_sum() array function in PHP will calculate the sum of all values within an array.

Example of array_sum()

<?php
$val1 = array(10, 5, 100);
$val2 = array(10.5, -5.5, 100);
echo "sum(val1) = ". array_sum($val1) . "<br />";
echo "sum(val2) = ". array_sum($val2) . "<br />";
?>

Output of the example

sum(val1) = 115

sum(val2) = 105