PHP array_sum() Function

Definition

The array_sum() function returns the sum of all the values in the array.

Syntax

PHP array_sum() Function has the following syntax.

array_sum(array)

Parameter

  • array - Required. Array to sum

Example 1

Sum an indexed array


<?php
    $a=array(5,15,25);
    echo array_sum($a);
?>

The code above generates the following result.

Example 2

Return the sum of all the values in the array (2.2+1.7+0.9):


<?php
   $a=array("a"=>2.2,"b"=>1.7,"c"=>0.9);
   echo array_sum($a);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions