nth

Definition

1
Arr::nth(array $array, int $A = 1, int $B = 0): array
Copied!

Aliases

1
even(array $array) -> nth($array, 2)
2
odd(array $array) -> nth($array, 2, 1)
Copied!

Description

Gets array elements with index matching condition $An + $B (preserving original keys)

Examples

1
$array = [
2
'a' => 0,
3
'b' => 1,
4
'c' => 2,
5
'd' => 3,
6
'e' => 4,
7
];
8
9
Arr::nth($array, 2, 3) ->
10
[
11
'c' => 2,
12
'e' => 4,
13
]
14
15
Arr::nth($array, 2) === Arr::even($array) ->
16
[
17
'a' => 0,
18
'c' => 2,
19
'e' => 4,
20
]
21
22
Arr::nth($array, 2, 1) === Arr::odd($array) ->
23
[
24
'b' => 1,
25
'd' => 3,
26
]
Copied!
Last modified 2yr ago
Copy link