AbstractMap
extends AbstractArray
in package
implements
MapInterface
This class provides a basic implementation of `MapInterface`, to minimize the effort required to implement this interface.
Interfaces, Classes, Traits and Enums
- MapInterface
- An object that maps keys to values.
Table of Contents
- $data : array<string|int, mixed>
- The items of this array.
- __construct() : mixed
- Constructs a new array object.
- 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.
- count() : int
- Returns the number of items in this array.
- get() : mixed|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.
- getIterator() : ArrayIterator<mixed, mixed>
- Returns an iterator for this array.
- isEmpty() : bool
- Returns `true` if this array is empty.
- keys() : array<string|int, mixed>
- Return an array of the keys contained in this map.
- offsetExists() : bool
- Returns `true` if the given offset exists in this array.
- offsetGet() : mixed|null
- Returns the value at the specified offset.
- offsetSet() : void
- Sets the given value to the given offset in the map.
- offsetUnset() : void
- Removes the given offset and its value from the array.
- put() : mixed|null
- Associates the specified value with the specified key in this map.
- putIfAbsent() : mixed|null
- Associates the specified value with the specified key in this map only if it is not already set.
- remove() : mixed|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() : mixed|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.
- serialize() : string
- Returns a serialized string representation of this array object.
- toArray() : array<string|int, mixed>
- Returns a native PHP array representation of this array object.
- unserialize() : void
- Converts a serialized string representation into an instance object.
Properties
$data
The items of this array.
protected
array<string|int, mixed>
$data
= []
Methods
__construct()
Constructs a new array object.
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
-
The initial items to add to this array.
Return values
mixed —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(mixed $key) : bool
Parameters
- $key : mixed
-
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(mixed $value) : bool
This performs a strict type check on the value.
Parameters
- $value : mixed
-
The value to check in the map.
Return values
bool —count()
Returns the number of items in this array.
public
count() : int
Tags
Return values
int —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(mixed $key[, mixed $defaultValue = null ]) : mixed|null
Parameters
- $key : mixed
-
The key to return from the map.
- $defaultValue : mixed = null
-
The default value to use if
$key
is not found.
Return values
mixed|null —the value or null
if the key could not be found.
getIterator()
Returns an iterator for this array.
public
getIterator() : ArrayIterator<mixed, mixed>
Tags
Return values
ArrayIterator<mixed, mixed> —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<string|int, mixed>
Return values
array<string|int, mixed> —offsetExists()
Returns `true` if the given offset exists in this array.
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
-
The offset to check.
Tags
Return values
bool —offsetGet()
Returns the value at the specified offset.
public
offsetGet(mixed $offset) : mixed|null
Parameters
- $offset : mixed
-
The offset for which a value should be returned.
Tags
Return values
mixed|null —the value stored at the offset, or null if the offset does not exist.
offsetSet()
Sets the given value to the given offset in the map.
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
-
The offset to set.
- $value : mixed
-
The value to set at the given offset.
Tags
Return values
void —offsetUnset()
Removes the given offset and its value from the array.
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
-
The offset to remove from the array.
Tags
Return values
void —put()
Associates the specified value with the specified key in this map.
public
put(mixed $key, mixed $value) : mixed|null
If the map previously contained a mapping for the key, the old value is replaced by the specified value.
Parameters
- $key : mixed
-
The key to put or replace in the map.
- $value : mixed
-
The value to store at
$key
.
Return values
mixed|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(mixed $key, mixed $value) : mixed|null
If there is already a value associated with $key
, this returns that
value without replacing it.
Parameters
- $key : mixed
-
The key to put in the map.
- $value : mixed
-
The value to store at
$key
.
Return values
mixed|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(mixed $key) : mixed|null
Parameters
- $key : mixed
-
The key to remove from the map.
Return values
mixed|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(mixed $key, mixed $value) : bool
This performs a strict type check on the value.
Parameters
- $key : mixed
-
The key to remove from the map.
- $value : mixed
-
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(mixed $key, mixed $value) : mixed|null
Parameters
- $key : mixed
-
The key to replace.
- $value : mixed
-
The value to set at
$key
.
Return values
mixed|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(mixed $key, mixed $oldValue, mixed $newValue) : bool
This performs a strict type check on the value.
Parameters
- $key : mixed
-
The key to remove from the map.
- $oldValue : mixed
-
The value to match.
- $newValue : mixed
-
The value to use as a replacement.
Return values
bool —true if the value was replaced.
serialize()
Returns a serialized string representation of this array object.
public
serialize() : string
Tags
Return values
string —a PHP serialized string.
toArray()
Returns a native PHP array representation of this array object.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —unserialize()
Converts a serialized string representation into an instance object.
public
unserialize(string $serialized) : void
Parameters
- $serialized : string
-
A PHP serialized string to unserialize.