Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_sum() Function

PHP array_sum() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Return the sum of all values in an array (5+15+25):

Run Example »


Definition and Usage

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


Syntax

array_sum(

array

)

Parameters Description
array Required. Specifies the array.

Technical Details

Return Value: Returns the sum of all values in the array.
PHP Version: 4.0.4+
Changelog: Versions before PHP 4.2.1 modified the passed array itself, converting its string values to numbers (in most cases to zero, depending on the value).

More examples

Example 1

Return the sum of all values in an array (52.2+13.7+0.9):

52.2,"b"=>13.7,"c"=>0.9); echo array_sum($a); ?>

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual