array_sum() function in PHP


The array_sum() function returns the sum of the values in an array. The returned value can be integer or float. It returns 0 if the array is empty.

Syntax

array_sum(arr)

Parameters

  • arr − the specified array

Return

The array_sum() function returns the sum of values. The returned value can be integer or float. It returns 0 if the array is empty.

Example

The following is an example −

 Live Demo

<?php
$arr = array(50, 100, 150, 300);
echo array_sum($arr);
?>

Output

The following is the output −

600

Example

Let us see another example −

 Live Demo

<?php
$arr = array("a"=>29.8,"b"=>66.4);
echo array_sum($arr);
?>

Output

The following is the output −

96.2

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Dec-2019

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements