Definition
The array_sum() function calculates the sum of all the values in an array.
Syntax
array_sum(array)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies an array. |
Example
<?php
// Example 1
$x = array(1, 2, 3, 4, 5);
echo array_sum($x);
echo "<br>";
// Example 2
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
echo array_sum($ages);
echo "<br>";