C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » PHP

array_sum() function in PHP

In this article, we are going to learn how to find sum of all array elements using array_sum() function in PHP?
Submitted by IncludeHelp, on January 03, 2018

Given a one dimensional array and we have to find sum of all elements using PHP.

array_sum() function

It is a built-in function of PHP, it returns sum of array elements.



It takes array as an argument and returns sum of all elements.


    Array elements: {10, 20, 30, 40, 50}
    Sum of all elements: 150


    //one dimensional array 
    $arr = array(10, 20, 30, 40, 50);
    //sum of the array elements
    $sum = array_sum($arr);
    echo ("Sum of array elements: " . $sum);


    Sum of array elements: 150

You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions