Open In App

PHP | Ds\Sequence sum() Function

Last Updated : 22 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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
<?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
<?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

Next Article

Similar Reads