Home Menu

array_sum

Calculate the sum of values in an array

Syntax

array_sum ( array $array ) : number

Parameters

array

The input array.

Return

Returns the sum of values as an integer or float; 0 if the array is empty.

Examples

1

<?

$array = array(0, 1, 2);

$return = array_sum($array);

echo $return;

?>
3

2

<?

$array = array("a" => 0.1, "b" => 1.2, "c" => 2.3);

$return = array_sum($array);

echo $return;

?>
3.6

3

<?

$array = array();

$return = array_sum($array);

echo $return;

?>
0

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms