Friday, October 17, 2025
HomeLanguagesPHP DsMap sum() Function

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. 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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS