PHP - Function array_sum()


Advertisements


Syntax

array_sum ( $array );

Definition and Usage

It calculates the sum of values in an array and returns the sum of values in an array as an integer or float.

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array.

Return Values

It returns the sum of values in an array as an integer or float.

Example

Try out following example −

<?php
   $ba = array(2, 4, 6, 8);
   echo "sum(ba) = " . array_sum($ba);
   print "\n" ;
   
   $ab = array("a" => 1.2, "b" => 2.3, "c" => 3.4);
   echo "sum(ab) = " . array_sum($ab);
?> 

This will produce the following result −

sum(ba) = 20
sum(ab) = 6.9

php_function_reference.htm

Advertisements