Array_sum

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

Array

array_sumCalculate the sum of values in an array

Description

Array_sumArray_sum

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

Due to all the downsides of adding a function to the Array prototype, I am updating this answer to provide an alternative that keeps the syntax similar to the syntax originally requested in the question. Arraysum (array $array): int float arraysum retourne la somme des valeurs du tableau array. The arraysum function returns the sum of all the values in the array. Arrays The sum of values in an array. If the array parameter value is an empty array, returns zero.

Array_sum

Parameters

Array Sum Python

array

The input array.

Return Values

Returns the sum of values as an integer or float; 0 if the array is empty.

Examples

Example #1 array_sum() examples

<?php
$a
= array(2, 4, 6, 8);
echo
'sum(a) = ' . array_sum($a) . 'n';
$b = array('a' => 1.2, 'b' => 2.3, 'c' => 3.4);
echo
'sum(b) = ' . array_sum($b) . 'n';
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.

Sum Elements Of Array

  • Array Functions
  • Deprecated