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.

Syntax:

array_sum($array_variable);

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

Example:

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

Program:

<?php
    //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);
?>

Output

    Sum of array elements: 150





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.




Comments and Discussions





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.