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
$map = new \Ds\Map([1 => 10, 2 => 20,
3 => 30]);
print_r( $map ->sum());
?>
|
Output:
60
Program 2:
<?php
$map = new \Ds\Map([1 => 10, 2 => 20.9,
3 => 30]);
print_r( $map ->sum());
?>
|
Output:
60.9
Reference: http://php.net/manual/en/ds-map.sum.php
Last Updated :
21 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...