You are here: Home / Topics / Program to find the sum of elements in an Array in PHP

Program to find the sum of elements in an Array in PHP

Filed under: PHP on 2022-11-19 12:30:07

The below program is to find the sum of elements in an array. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.

array_sum() function in PHP 

Example

<!DOCTYPE html>
<html>
<body>

<?php    
$numbers=array("100","160","20","67");    
echo "Sum of array elements is: ";
echo array_sum($numbers);
?>    

</body>
</html>
 

Output

Sum of array elements is: 347


About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.