Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_sum()

Example

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

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

Definition and Usage

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

Syntax

array_sum(array)

Parameter Values

 

Parameter

Description

array

Required. Specifies the array to sum.

Technical Details

Return Value:

Returns the total sum of all values in an array.

PHP Version:

4.0.4+

PHP Changelog:

In PHP versions prior to 4.2.1, the function modified the original array and converted strings to numbers, which often resulted in them being converted to zero depending on their value.

More Examples

Example

Return the total of all 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);
?>