PHP | Ds\Deque sum() Function Last Updated : 14 Aug, 2019 Comments Improve Suggest changes Like Article Like Report The Ds\Deque::sum() function is an inbuilt function in PHP which is used to return the sum of all elements present in the Deque. Syntax: public Ds\Deque::sum( void ) : number Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all Deque elements. Below programs illustrate the Ds\Deque::sum() function in PHP: Program 1: PHP <?php // Declare a deque $deck = new \Ds\Deque([5, 6, 3, 2, 7, 1]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); echo("Sum of all Deque elements: "); // Use sum() function to add all // Deque elements var_dump($deck->sum()); ?> Output: Elements of Deque Ds\Deque Object ( [0] => 5 [1] => 6 [2] => 3 [3] => 2 [4] => 7 [5] => 1 ) Sum of all Deque elements: int(24) Program 2: PHP <?php // Declare a deque $deck = new \Ds\Deque([1.5, 6.3, 2.3, 7.2, 4.7, 9.3]); echo("Elements of Deque\n"); // Display the Deque elements print_r($deck); echo("Sum of all Deque elements: "); // Use sum() function to add all // Deque elements var_dump($deck->sum()); ?> Output: Elements of Deque Ds\Deque Object ( [0] => 1.5 [1] => 6.3 [2] => 2.3 [3] => 7.2 [4] => 4.7 [5] => 9.3 ) Sum of all Deque elements: float(31.3) Reference: http://php.net/manual/en/ds-deque.sum.php Comment More infoAdvertise with us Next Article PHP | DsSequence sum() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_deque Similar Reads PHP | DsDeque sum() Function The Ds\Deque::sum() function is an inbuilt function in PHP which is used to return the sum of all elements present in the Deque. Syntax: public Ds\Deque::sum( void ) : number Parameters: This function does not accept any parameter. Return Value: This function returns the sum of all Deque elements. B 2 min read PHP | DsSequence 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 e 1 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read PHP DsSet sum() Function The Ds\Set::sum() function of Ds\Set class in PHP is an inbuilt function which is used to find the sum of all of the elements present in a Set. Syntax: number public Ds\Set::sum ( void ) Parameter: This function does not accepts any parameter. Return Value: This function returns the sum of the value 1 min read PHP DsMap sum() Function The Ds\Map::sum() function of PHP is used to get the sum of all of the values present in the Map instance. Syntax: number public Ds\Map::sum ( void ) Parameters: This function does not accepts any parameter. Return value: This function returns the sum of all of the values present in the Map instance 1 min read PHP | DsDeque push() Function The Ds\Deque::push() function is an inbuilt function in PHP which is used to add the elements to the Deque by appending an element at the end of the Deque. Syntax: public Ds\Deque::push( $values ) : void Parameters: This function accepts single parameter $values which holds the elements to be added 2 min read Like