array_sum() function in php || PHP Array Sum Function
×


array_sum() function in php

2172

array_sum() function of PHP is used to retrieve the sum of all elements of a PHP array. It is an inbuilt function of PHP.

Syntax:

array_sum($array);

here,

$array is a PHP array.


Example 1:

<?php
$arr1=array(1,2,3,4,5,6,7,8,9);
$result=array_sum($arr1);
echo "Sum is : ".$result;
?>

Output:


Example 2:

<?php
$arr1=array("e1"=>25,"e2"=>50,"e3"=>75,"e4"=>15,"e5"=>35,"e6"=>1);
$result=array_sum($arr1);
echo "Sum is : ".$result;
?>

Output:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments