Documentation

MapInterface extends ArrayInterface

An object that maps keys to values.

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

Tags
template

T

extends

ArrayInterface<T>

Table of Contents

clear()  : void
Removes all items from this array.
containsKey()  : bool
Returns `true` if this map contains a mapping for the specified key.
containsValue()  : bool
Returns `true` if this map maps one or more keys to the specified value.
get()  : T|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.
isEmpty()  : bool
Returns `true` if this array is empty.
keys()  : array<int, array-key>
Return an array of the keys contained in this map.
put()  : T|null
Associates the specified value with the specified key in this map.
putIfAbsent()  : T|null
Associates the specified value with the specified key in this map only if it is not already set.
remove()  : T|null
Removes the mapping for a key from this map if it is present.
removeIf()  : bool
Removes the entry for the specified key only if it is currently mapped to the specified value.
replace()  : T|null
Replaces the entry for the specified key only if it is currently mapped to some value.
replaceIf()  : bool
Replaces the entry for the specified key only if currently mapped to the specified value.
toArray()  : array<array-key, T>
Returns a native PHP array representation of this array object.

Methods

clear()

Removes all items from this array.

public clear() : void
Return values
void

containsKey()

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

public containsKey(string|int $key) : bool
Parameters
$key : string|int

The key to check in the map.

Return values
bool

containsValue()

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

public containsValue(T $value) : bool

This performs a strict type check on the value.

Parameters
$value : T

The value to check in the map.

Return values
bool

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(string|int $key[, T|null $defaultValue = null ]) : T|null
Parameters
$key : string|int

The key to return from the map.

$defaultValue : T|null = null

The default value to use if $key is not found.

Return values
T|null

the value or null if the key could not be found.

isEmpty()

Returns `true` if this array is empty.

public isEmpty() : bool
Return values
bool

keys()

Return an array of the keys contained in this map.

public keys() : array<int, array-key>
Return values
array<int, array-key>

put()

Associates the specified value with the specified key in this map.

public put(string|int $key, T $value) : T|null

If the map previously contained a mapping for the key, the old value is replaced by the specified value.

Parameters
$key : string|int

The key to put or replace in the map.

$value : T

The value to store at $key.

Return values
T|null

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.

public putIfAbsent(string|int $key, T $value) : T|null

If there is already a value associated with $key, this returns that value without replacing it.

Parameters
$key : string|int

The key to put in the map.

$value : T

The value to store at $key.

Return values
T|null

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.

public remove(string|int $key) : T|null
Parameters
$key : string|int

The key to remove from the map.

Return values
T|null

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.

public removeIf(string|int $key, T $value) : bool

This performs a strict type check on the value.

Parameters
$key : string|int

The key to remove from the map.

$value : T

The value to match.

Return values
bool

true if the value was removed.

replace()

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

public replace(string|int $key, T $value) : T|null
Parameters
$key : string|int

The key to replace.

$value : T

The value to set at $key.

Return values
T|null

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(string|int $key, T $oldValue, T $newValue) : bool

This performs a strict type check on the value.

Parameters
$key : string|int

The key to remove from the map.

$oldValue : T

The value to match.

$newValue : T

The value to use as a replacement.

Return values
bool

true if the value was replaced.

toArray()

Returns a native PHP array representation of this array object.

public toArray() : array<array-key, T>
Return values
array<array-key, T>

Search results