PHP array_sum() Function

PHP array_sum() Function

The array_sum() function in PHP is used to calculate the sum of values in an array.

Syntax

array_sum ( array $array )

Parameter

array(required)- This array represents the input array.

Return

This function returns the sum of values as an integer or float value, or it returns 0 if the specified array is empty.

Example 1

 

Output

Input Array
 Array
 (
     [0] => 12
     [1] => 14
     [2] => 6
     [3] => 8 
 )
 The sum = 40 

Example 2

 

Output

Input Array
 Array
 (
     [0] => 1.0912
     [1] => 2.0314
     [2] => 6.5456
     [3] => 8.9876 
 )
 The sum = 18.6558 

Example 3

 

Output

Input Array
 Array
 (
     [0] => Reema
     [1] => Sonoo
     [2] => Sukla
     [3] => VArun
 ) 
 The sum = 0 

Example 4

 

Output

Input Array
 Array
 (
     [0] => 
 )
 The sum = 0