NumberMap.phpView Source

Show: PublicProtectedPrivateinherited
Table of Contents

\Ulrichsg\Collections\NumberMap

Package:
A map that contains only numeric values, and supports mathematical operations.
Parent(s)
\Ulrichsg\Collections\Map
License
MIT  
Link
https://github.com/ulrichsg/php-collections  
Version
 

Methods

methodpublic__construct(array $data = array(), mixed $default = 0) : void

Creates a new NumberMap with the given array as its contents. Omitting the argument creates an empty map.

Parameters
NameTypeDescription
$dataarray
$defaultmixed
Throws
ExceptionDescription
\InvalidArgumentExceptionif $default or one of the array values is not numeric
methodpublicadd(mixed $key, mixed $value) : void

Adds the given value to the one associated to the given key.

If the key is not in the map yet, put it in and assume the map-wide default value.
Parameters
NameTypeDescription
$keymixed
$valuemixed
Throws
ExceptionDescription
\InvalidArgumentExceptionif $value is not numeric
methodpublicset(mixed $key, mixed $value) : void

Puts the given key-value pair into the map.

Parameters
NameTypeDescription
$keymixed
$valuemixed
Throws
ExceptionDescription
\InvalidArgumentExceptionif $value is not numeric
methodpublicsum() : mixed

Returns the sum of all values in the map.

Returns
TypeDescription
mixed
Documentation was generated by phpDocumentor 2.0.0b7 .