isAssoc

Definition

1
Arr::isAssoc(array $array, bool $strict = false): bool
Copied!

Description

Check if array is associative

Examples

1
$array = ['a' => 1, 'b' => 3, 1 => 'd', 'c'];
2
3
Arr::isAssoc($array) -> true
4
Arr::isAssoc($array, true) -> true
5
6
7
$array = [1 => 1, 2 => 2, 3 => 3];
8
9
// There are no string keys
10
Arr::isAssoc($array) -> false
11
12
// However indexes are not automatically generated (starting from 0 up)
13
Arr::isAssoc($array, true) -> true
14
15
// In this case keys are automatically generated
16
Arr::isAssoc([1, 2, 3], true) -> false
17
18
// Which is equal to this
19
Arr::isAssoc([0 => 1, 1 => 2, 2 => 3], true) -> false
Copied!
Last modified 2yr ago
Copy link