has

Definition

1
Arr::has(array $array, mixed $keys): bool
Copied!

Description

Check if specified (nested) key(s) exists in array
$keys argument is parsed using getKeysArray method

Examples

1
$array = [
2
'foo' => [
3
1,
4
'test' => [
5
'abc' => 2,
6
'def'
7
],
8
[
9
'bar' => true
10
],
11
],
12
];
13
14
Arr::has($array, 'foo') -> true
15
Arr::has($array, 'foo.0') -> true
16
Arr::has($array, 'foo.test') -> true
17
Arr::has($array, 'foo.test.abc') -> true
18
Arr::has($array, ['foo', 1, 'bar']) -> true
19
20
Arr::has($array, 'test') -> false
21
Arr::has($array, []) -> false
22
Arr::has($array, 'not.existing.key') -> false
Copied!
Last modified 2yr ago
Copy link