PHP array_sum() function

P
PHP array_slice() function
PHP array_udiff() function

The array_sum function calculates and returns the sum of all the values of the given array.

What is the syntax of the array_sum function in PHP?

array_sum(array)
ParameterDetails
arrayThe array to calculate the sum of – Required
array_sum function in PHP

Examples of array_sum function

Example 1. Return sum of array values 2+7+15

<?php
$arr=array(2,7,15);
echo array_sum($arr);
?>

Example 2. Return sum of associative array values 2.1+7.2+15.3

<?php
$arr=array("a"=>2.1,"b"=>7.2,"c"=>15.3);
echo array_sum($arr);
?>
PHP array_slice() function
PHP array_udiff() function

Add comment

Tutor Network

Share this

Learn PHP from A to Z