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. The return type of the function can be int or float depending on the type of value present in the Map.
Below programs illustrate the Ds\Map::sum() function:
Program 1:
<?php // PHP program to illustrate sum() function $map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30]); // The function returns an int which is // the sum of values present in the Map print_r($map->sum()); ?> |
Output:
60
Program 2:
<?php // PHP program to illustrate sum() function $map = new \Ds\Map([1 => 10, 2 => 20.9, 3 => 30]); // The function returns a float value which is // the sum of values present in the Map print_r($map->sum()); ?> |
Output:
60.9
Reference: http://php.net/manual/en/ds-map.sum.php
Recommended Posts:
- PHP | Ds\Sequence sum() Function
- PHP | Ds\Vector sum() Function
- PHP | Ds\Deque sum() Function
- PHP Ds\Set sum() Function
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | Sum of digits of a number
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() 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.

