X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP array_sum() Function

PHP Array Reference PHP Array Reference

Example

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

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

Run example »

Definition and Usage

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


Syntax

array_sum(array)

Parameter Description
array Required. Specifies an array

Technical Details

Return Value: Returns the sum of all the values in an array
PHP Version: 4.0.4+
Changelog: PHP versions prior to 4.2.1 modified the passed array itself and converted strings to numbers (which often converted them to zero, depending on their value)


More Examples

Example 1

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

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

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook