MapInterface
An object that maps keys to values.
A map cannot contain duplicate keys; each key can map to at most one value.
- Full name:
\Ramsey\Collection\Map\MapInterface
- Parent interfaces:
\Ramsey\Collection\ArrayInterface
Methods
containsKey
Returns true
if this map contains a mapping for the specified key.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to check in the map. |
containsValue
Returns true
if this map maps one or more keys to the specified value.
This performs a strict type check on the value.
Parameters:
Parameter | Type | Description |
---|---|---|
$value |
\Ramsey\Collection\Map\T | The value to check in the map. |
keys
Return an array of the keys contained in this map.
get
Returns the value to which the specified key is mapped, null
if this
map contains no mapping for the key, or (optionally) $defaultValue
if
this map contains no mapping for the key.
public get(array-key $key, \Ramsey\Collection\Map\T|null $defaultValue = null): \Ramsey\Collection\Map\T|null
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to return from the map. |
$defaultValue |
\Ramsey\Collection\Map\T|null | The default value to use if $key is not found. |
Return Value:
the value or null
if the key could not be found.
put
Associates the specified value with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to put or replace in the map. |
$value |
\Ramsey\Collection\Map\T | The value to store at $key . |
Return Value:
the previous value associated with key, or null
if
there was no mapping for $key
.
putIfAbsent
Associates the specified value with the specified key in this map only if it is not already set.
If there is already a value associated with $key
, this returns that
value without replacing it.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to put in the map. |
$value |
\Ramsey\Collection\Map\T | The value to store at $key . |
Return Value:
the previous value associated with key, or null
if
there was no mapping for $key
.
remove
Removes the mapping for a key from this map if it is present.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to remove from the map. |
Return Value:
the previous value associated with key, or null
if
there was no mapping for $key
.
removeIf
Removes the entry for the specified key only if it is currently mapped to the specified value.
This performs a strict type check on the value.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to remove from the map. |
$value |
\Ramsey\Collection\Map\T | The value to match. |
Return Value:
true if the value was removed.
replace
Replaces the entry for the specified key only if it is currently mapped to some value.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to replace. |
$value |
\Ramsey\Collection\Map\T | The value to set at $key . |
Return Value:
the previous value associated with key, or null
if
there was no mapping for $key
.
replaceIf
Replaces the entry for the specified key only if currently mapped to the specified value.
public replaceIf(array-key $key, \Ramsey\Collection\Map\T $oldValue, \Ramsey\Collection\Map\T $newValue): bool
This performs a strict type check on the value.
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
array-key | The key to remove from the map. |
$oldValue |
\Ramsey\Collection\Map\T | The value to match. |
$newValue |
\Ramsey\Collection\Map\T | The value to use as a replacement. |
Return Value:
true if the value was replaced.
Inherited methods
clear
Removes all items from this array.
toArray
Returns a native PHP array representation of this array object.
isEmpty
Returns true
if this array is empty.
Automatically generated on 2025-03-18