interface MapInterface implements ArrayInterface (View source)

An object that maps keys to values

A map cannot contain duplicate keys; each key can map to at most one value.

Methods

void
clear()

Remove all the elements from this array object

toArray()

Returns a native PHP array containing all of the elements in this array object

bool
isEmpty()

Returns true if this array object contains no elements

bool
containsKey(mixed $key)

Returns true if this map contains a mapping for the specified key

bool
containsValue(mixed $value)

Returns true if this map maps one or more keys to the specified value

mixed|null
get($key, $defaultValue = null)

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

mixed
put(mixed $key, mixed $value)

Associates the specified value with the specified key in this map

mixed
putIfAbsent(mixed $key, mixed $value)

If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value

mixed
remove(mixed $key)

Removes the mapping for a key from this map if it is present

bool
removeIf(mixed $key, mixed $value)

Removes the entry for the specified key only if it is currently mapped to the specified value

mixed
replace(mixed $key, mixed $value)

Replaces the entry for the specified key only if it is currently mapped to some value

bool
replaceIf(mixed $key, mixed $oldValue, mixed $newValue)

Replaces the entry for the specified key only if currently mapped to the specified value

Details

void clear()

Remove all the elements from this array object

Return Value

void

toArray()

Returns a native PHP array containing all of the elements in this array object

bool isEmpty()

Returns true if this array object contains no elements

Return Value

bool

bool containsKey(mixed $key)

Returns true if this map contains a mapping for the specified key

Parameters

mixed $key

Return Value

bool

bool containsValue(mixed $value)

Returns true if this map maps one or more keys to the specified value

This performs a strict type check on the value.

Parameters

mixed $value

Return Value

bool

mixed|null get($key, $defaultValue = null)

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

Parameters

$key
$defaultValue

Return Value

mixed|null

mixed put(mixed $key, mixed $value)

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

mixed $key
mixed $value

Return Value

mixed the previous value associated with key, or null if there was no mapping for key

mixed putIfAbsent(mixed $key, mixed $value)

If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value

Parameters

mixed $key
mixed $value

Return Value

mixed the previous value associated with key, or null if there was no mapping for key

mixed remove(mixed $key)

Removes the mapping for a key from this map if it is present

Parameters

mixed $key

Return Value

mixed the previous value associated with key, or null if there was no mapping for key

bool removeIf(mixed $key, mixed $value)

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

mixed $key
mixed $value

Return Value

bool true if the value was removed

mixed replace(mixed $key, mixed $value)

Replaces the entry for the specified key only if it is currently mapped to some value

Parameters

mixed $key
mixed $value

Return Value

mixed the previous value associated with key, or null if there was no mapping for key

bool replaceIf(mixed $key, mixed $oldValue, mixed $newValue)

Replaces the entry for the specified key only if currently mapped to the specified value

This performs a strict type check on the value.

Parameters

mixed $key
mixed $oldValue
mixed $newValue

Return Value

bool true if the value was replaced