PHP | Ds\Sequence sum() Function
The Ds\Sequence::sum() function is an inbuilt function in PHP which is used to return the sum of all values of the sequence.
Syntax:
number abstract public Ds\Sequence::sum( void )
Parameters: This function does not accept any parameters.
Return value: This function returns the sum of all sequence elements in form of integer or float.
Below programs illustrate the Ds\Sequence::sum() function in PHP:
Program 1:
<?php // Create new sequence $seq = new \Ds\Vector([5, 7, 8, 14, 23]); // Use sum() function to find // the sum of sequence element var_dump($seq->sum()); ?> |
Output:
int(57)
Program 2:
<?php // Create new sequence $seq = new \Ds\Vector([5, 7.5, 8.4, 14, 23]); // Use sum() function to find // the sum of sequence element var_dump($seq->sum()); ?> |
Output:
float(57.9)
Reference: http://php.net/manual/en/ds-sequence.sum.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- PHP | max( ) Function
- p5.js | int() function
- p5.js | str() function
- D3.js | d3.mean() function
- PHP | Ds\Map xor() Function
- PHP Ds\Map sum() Function
- PHP | Ds\Map first() Function
- p5.js | hex() function
- CSS | var() Function
- D3.js | d3.sum() function
- p5.js | value() Function
- D3.js | d3.map.set() Function
- PHP | end() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



