Friday, May 29, 2026
HomeLanguagesPHP | DsSequence sum() Function

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

RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS