class AssociativeArrayMap extends AbstractMap (View source)

AssociativeArrayMap represents a standard associative array object.

Properties

protected array $data The items of this array. from AbstractArray

Methods

__construct(array $data = [])

Constructs a new array object.

getIterator()

Returns an iterator for this array.

bool
offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

mixed|null
offsetGet(mixed $offset)

Returns the value at the specified offset.

void
offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the map.

void
offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

string
serialize()

Returns a serialized string representation of this array object.

void
unserialize(string $serialized)

Converts a serialized string representation into an instance object.

int
count()

Returns the number of items in this array.

void
clear()

Removes all items from this array.

array
toArray()

Returns a native PHP array representation of this array object.

bool
isEmpty()

Returns true if this array is empty.

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.

array
keys()

Return an array of the keys contained in this map.

mixed|null
get(mixed $key, mixed $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|null
put(mixed $key, mixed $value)

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

mixed|null
putIfAbsent(mixed $key, mixed $value)

Associates the specified value with the specified key in this map only if it is not already set.

mixed|null
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|null
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 The initial items to add to this array.

Traversable getIterator()

Returns an iterator for this array.

Return Value

Traversable

bool offsetExists(mixed $offset)

Returns true if the given offset exists in this array.

Parameters

mixed $offset The offset to check.

Return Value

bool

mixed|null offsetGet(mixed $offset)

Returns the value at the specified offset.

Parameters

mixed $offset The offset for which a value should be returned.

Return Value

mixed|null the value stored at the offset, or null if the offset does not exist.

void offsetSet(mixed|null $offset, mixed $value)

Sets the given value to the given offset in the map.

Parameters

mixed|null $offset The offset to set. If null, the value may be set at a numerically-indexed offset.
mixed $value The value to set at the given offset.

Return Value

void

Exceptions

InvalidArgumentException if the offset provided is null.

void offsetUnset(mixed $offset)

Removes the given offset and its value from the array.

Parameters

mixed $offset The offset to remove from the array.

Return Value

void

string serialize()

Returns a serialized string representation of this array object.

Return Value

string a PHP serialized string.

void unserialize(string $serialized)

Converts a serialized string representation into an instance object.

Parameters

string $serialized A PHP serialized string to unserialize.

Return Value

void

int count()

Returns the number of items in this array.

Return Value

int

void clear()

Removes all items from this array.

Return Value

void

array toArray()

Returns a native PHP array representation of this array object.

Return Value

array

bool isEmpty()

Returns true if this array is empty.

Return Value

bool

bool containsKey(mixed $key)

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

Parameters

mixed $key The key to check in the map.

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 The value to check in the map.

Return Value

bool

array keys()

Return an array of the keys contained in this map.

Return Value

array

mixed|null get(mixed $key, mixed $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

mixed $key The key to return from the map.
mixed $defaultValue The default value to use if $key is not found.

Return Value

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

mixed|null 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 The key to put or replace in the map.
mixed $value The value to store at $key.

Return Value

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

mixed|null putIfAbsent(mixed $key, mixed $value)

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

mixed $key The key to put in the map.
mixed $value The value to store at $key.

Return Value

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

mixed|null remove(mixed $key)

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

Parameters

mixed $key The key to remove from the map.

Return Value

mixed|null 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 The key to remove from the map.
mixed $value The value to match.

Return Value

bool true if the value was removed.

mixed|null replace(mixed $key, mixed $value)

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

Parameters

mixed $key The key to replace.
mixed $value The value to set at $key.

Return Value

mixed|null 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 The key to remove from the map.
mixed $oldValue The value to match.
mixed $newValue The value to use as a replacement.

Return Value

bool true if the value was replaced.