PHP array_sum function

Last Updated: February 15, 2022

array_sum — Calculate the sum of the array

Syntax

 array_sum(array $array): int|float

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

Parameters

 

Parameter Description
array target array

Return Value

returns the sum of the elements of the array

Example

$arr1 = array(1,2,3 );
print_r(array_sum($arr1));

Output

6
Test