abstract class AbstractMap extends AbstractArray implements MapInterface (View source)

This class provides an implementation of the MapInterface, to minimize the effort required to implement this interface

Properties

protected array $data from AbstractArray

Methods

__construct(array $data = [])

Constructs a new array object

getIterator()

Returns a new iterator from this array

bool
offsetExists(mixed $offset)

Checks whether the specified offset exists in the array

mixed
offsetGet(mixed $offset)

Returns the value stored at the specified offset in the array

offsetSet(mixed $offset, mixed $value)

Sets the specified offset in the map with the given value

offsetUnset(mixed $offset)

Removes the specified offset and its value from the map

string
serialize()

Converts this map object to a string when the object is serialized with serialize()

unserialize(string $serialized)

Re-constructs the object from its serialized form

int
count()

Returns the number of elements contained in this array

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

__construct(array $data = [])

Constructs a new array object

Parameters

array $data

ArrayIterator getIterator()

Returns a new iterator from this array

Return Value

ArrayIterator

bool offsetExists(mixed $offset)

Checks whether the specified offset exists in the array

Parameters

mixed $offset

Return Value

bool

mixed offsetGet(mixed $offset)

Returns the value stored at the specified offset in the array

Parameters

mixed $offset

Return Value

mixed

offsetSet(mixed $offset, mixed $value)

Sets the specified offset in the map with the given value

Parameters

mixed $offset
mixed $value

Exceptions

InvalidArgumentException

offsetUnset(mixed $offset)

Removes the specified offset and its value from the map

Parameters

mixed $offset

string serialize()

Converts this map object to a string when the object is serialized with serialize()

Return Value

string

unserialize(string $serialized)

Re-constructs the object from its serialized form

Parameters

string $serialized

int count()

Returns the number of elements contained in this array

Return Value

int

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