get → getNestedElement

Definition

1
Arr::getNestedElement(array|ArrayAccess $array, mixed $keys, mixed $default = null): mixed
Copied!

Aliases

1
get($array, $keys, $default = null) -> getNestedElement($array, $keys, $default)
Copied!

Description

Get nested array element using specified keys or return $default value if it does not exists.
$keys argument is parsed using getKeysArray method

Examples

1
$array = ['key1' => ['key2' => ['key3' => ['test']]]];
2
3
Arr::getNestedElement($array, 'key1.key2.key3') -> ['test']
4
5
Arr::getNestedElement($array, 'key1.key2.key3.0') -> 'test'
6
7
Arr::getNestedElement($array, ['nonexistent', 'key'], 'default') -> 'default'
8
9
Arr::getNestedElement($array, 'nonexistent.key.without.default') -> null
Copied!
Last modified 2yr ago
Copy link