class HashMap extends BaseMap

An associative array allowing the use of chained

This class can be used as a service container, an application context, to store configuration.

Traits

Constants

CB_ZERO_ARG

Methods

int
count()

No description

array
toArray()

Gets a copy of the internal map.

mixed
first()

No description

mixed
firstOr(mixed $default)

No description

bool
any(callable $callable)

Determines if at least an element of the collection satisfies a condition.

bool
all(callable $callable)

Determines if all elements of the collection satisfies a condition.

static BaseCollection
from(iterable|object|null $from)

Converts deeply an element to a map.

bool
isEmpty()

Determine if a collection is empty.

mixed
get(mixed $key)

Get the value at the specified key.

mixed
getOr(mixed $key, mixed $defaultValue)

Get the value at the specified key.

set(mixed $key, mixed $value)

Set the specified value at the specified key.

unset(mixed $key)

This method returns the instance itself, so you can use it in fluent pattern.

bool
has(mixed $key)

Determine if the specified key exists.

bool
contains(mixed $value)

Determine if the specified value exists.

bool
offsetExists(mixed $offset)

No description

from  BaseMap
mixed
offsetGet(mixed $offset)

No description

from  BaseMap
void
offsetSet(mixed $offset, mixed $value)

Assign a value to the specified offset

from  BaseMap
void
offsetUnset(mixed $offset)

No description

from  BaseMap
__construct(iterable $iterable = [])

No description

clear()

No description

merge(iterable $iterable)

Merge the specified map with the current map.

update(iterable $iterable)

Merge the specified map with the current bag.

map(callable $callable)

No description

filter(callable $callable)

No description

mapKeys(callable $callable)

No description

mapValuesAndKeys(callable $callable)

No description

flatMap(callable $callable)

No description

mapToVector(callable $callable)

No description

filterKeys(callable $callable)

No description

getIterator()

No description

Details

at line 118
int count()

No description

Return Value

int

at line 170
array toArray()

Gets a copy of the internal map.

Scalar values (int, strings) are cloned. Objects are references to a specific objet, not a clone.

Return Value

array

in WithCollection at line 15
mixed first()

No description

Return Value

mixed

in WithCollection at line 23
mixed firstOr(mixed $default)

No description

Parameters

mixed $default

Return Value

mixed

in WithCollection at line 45
bool any(callable $callable)

Determines if at least an element of the collection satisfies a condition.

The execution of callbacks stop after a callable returned true.

Parameters

callable $callable

A method returning a boolean with key and value or only value as arguments.

Return Value

bool

True if callback is true for at least one of the elements

Exceptions

ReflectionException

in WithCollection at line 78
bool all(callable $callable)

Determines if all elements of the collection satisfies a condition.

The execution of callbacks stop after a callable returned false.

Parameters

callable $callable

A method returning a boolean with key and value or only value as arguments.

Return Value

bool

True if callback is true for all the elements

Exceptions

ReflectionException

at line 65
static BaseCollection from(iterable|object|null $from)

Converts deeply an element to a map.

If $from is an object or iterable, each element will be:

  • converted to an array (deep array) if iterable or object
  • kept as is if it's a scalar

Parameters

iterable|object|null $from

Return Value

BaseCollection

The collection with the elements from the iterable

at line 122
bool isEmpty()

Determine if a collection is empty.

Return Value

bool

true if the collection has 0 element; if not, false.

at line 78
mixed get(mixed $key)

Get the value at the specified key.

Parameters

mixed $key

The key

Return Value

mixed

The value

at line 86
mixed getOr(mixed $key, mixed $defaultValue)

Get the value at the specified key.

Parameters

mixed $key

The key

mixed $defaultValue

The value to return if the key doesn't exist.

Return Value

mixed

When the key exists, the value at that key; otherwise, the default value

at line 90
BaseMap set(mixed $key, mixed $value)

Set the specified value at the specified key.

This method returns the instance itself, so you can use it in fluent pattern.

Parameters

mixed $key

The key

mixed $value

The value

Return Value

BaseMap

The map

at line 100
BaseMap unset(mixed $key)

This method returns the instance itself, so you can use it in fluent pattern.

Parameters

mixed $key

Return Value

BaseMap

The map

at line 106
bool has(mixed $key)

Determine if the specified key exists.

Parameters

mixed $key

The key to fetch

Return Value

bool

true if the key exists; otherwise, false.

at line 110
bool contains(mixed $value)

Determine if the specified value exists.

Parameters

mixed $value

Return Value

bool

true if the value exists; otherwise, false

in BaseMap at line 90
bool offsetExists(mixed $offset)

No description

Parameters

mixed $offset

The offset to assign the value to

Return Value

bool

true if the offset exists; otherwise, false

in BaseMap at line 100
mixed offsetGet(mixed $offset)

No description

Parameters

mixed $offset

The offset to assign the value to

Return Value

mixed

The value at that offset

in BaseMap at line 112
void offsetSet(mixed $offset, mixed $value)

Assign a value to the specified offset

Parameters

mixed $offset

The offset to assign the value to

mixed $value

The value to set

Return Value

void

in BaseMap at line 121
void offsetUnset(mixed $offset)

No description

Parameters

mixed $offset

The offset to assign the value to

Return Value

void

at line 31
__construct(iterable $iterable = [])

No description

Parameters

iterable $iterable

at line 126
HashMap clear()

No description

Return Value

HashMap

at line 139
HashMap merge(iterable $iterable)

Merge the specified map with the current map.

If a key already exists, the value already set is kept.

Parameters

iterable $iterable

Return Value

HashMap

See also

update() when you need to update with the new value.

at line 154
HashMap update(iterable $iterable)

Merge the specified map with the current bag.

If a key already exists, the value is updated with the new one.

Parameters

iterable $iterable

Return Value

HashMap

See also

merge() when you need to keep old value.

at line 178
HashMap map(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 182
HashMap filter(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 194
HashMap mapKeys(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 203
HashMap mapValuesAndKeys(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 219
HashMap flatMap(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 235
Vector mapToVector(callable $callable)

No description

Parameters

callable $callable

Return Value

Vector

at line 250
HashMap filterKeys(callable $callable)

No description

Parameters

callable $callable

Return Value

HashMap

at line 260
Traversable getIterator()

No description

Return Value

Traversable