PHP Ds\Set sum() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 values present in a Set. The return type of the function can be integer or float depending on the type of values present in the Set instance. Below programs illustrate the Ds\Set::sum() function: Program 1: php <?php // Declare an empty set $set = new \Ds\Set([1, 2, 3, 4, 5]); // Print the sum of all values echo("Sum of all values is: "); print_r($set->sum()); ?> Output: Sum of all values is: 15 Program 2: php <?php // Declare an empty set $set = new \Ds\Set([1.1, 2.2, 3.5, 4.9, 5]); // Print the sum of all values echo("Sum of all values is: "); print_r($set->sum()); ?> Output: Sum of all values is: 16.7 Reference: https://www.php.net/manual/en/ds-set.sum.php Comment More infoAdvertise with us Next Article PHP | Ds\Sequence sum() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Similar Reads 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 e 1 min read 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 e 1 min read PHP Ds\Map 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 Ds\Map 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 | Ds\Set add() Function The Ds\Set::add() function is an inbuilt function in PHP which is used to add values to the set. Syntax: void public Ds\Set::add( $values ) Parameters: This function accepts a single parameter $values which holds many values to be added in the set. Return value: This function does not return any val 1 min read PHP | Ds\Set add() Function The Ds\Set::add() function is an inbuilt function in PHP which is used to add values to the set. Syntax: void public Ds\Set::add( $values ) Parameters: This function accepts a single parameter $values which holds many values to be added in the set. Return value: This function does not return any val 1 min read Like