Thursday, 4 January 2018

array_sum() function | PHP

Tags

The array_sum() function is an inbuilt function in PHP. This function is used to calculate the sum of the elements of an array.

Example:
array_sum($array)

$array : An array whose sum of values to be found.

This function takes an array as parameter and return the sum of the elements of the array.

PROGRAM:

<?php


$array1=array(23,45,66,54,67,345);
echo nl2br("rn The elements of the array is given below: rn rn");
print_r($array1);

$sum=array_sum($array1);

echo nl2br("rn rn The sum of the elements of arrays is: rn rn");
echo $sum;

?>


OUTPUT:




EmoticonEmoticon