A::get()
Gets an element of an array by key
A::get(array $array, array|string|int|null $key, mixed $default = null)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $arrayrequired | array |
no default value | |
| $key | arrayorstringorintornull |
no default value | Key, dot notation path or list of keys; null returns the entire array |
| $default | mixed |
null
|
Parent class
Examples
$array = [
'cat' => 'miao',
'dog' => 'wuff',
'bird' => 'tweet'
];
echo A::get($array, 'cat');
// output: 'miao'
echo A::get($array, 'elephant', 'shut up');
// output: 'shut up'
$catAndDog = A::get($array, ['cat', 'dog']);
// result: ['cat' => 'miao', 'dog' => 'wuff'];