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

array_sum() function in php

Last Updated by Pooja Chikara 16-Apr-20

0 356


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:

array_sum() function in php


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:

array_sum() function in php


Share:


Leave a Reply


Comments
    Waiting for your comments