<?php
function skipFromBack(array $array, int $skip): array {
$result = [];
for ($index = array_key_last($array); $index > -1; $index -= 1 + $skip) {
$result[] = $array[$index];
}
return array_reverse($result);
}
$array = range(0, 15);
foreach ([0, 1, 2, 3] as $skip) {
var_export(skipFromBack($array, $skip));
echo "\n---\n";
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
14 => 14,
15 => 15,
)
---
array (
0 => 1,
1 => 3,
2 => 5,
3 => 7,
4 => 9,
5 => 11,
6 => 13,
7 => 15,
)
---
array (
0 => 0,
1 => 3,
2 => 6,
3 => 9,
4 => 12,
5 => 15,
)
---
array (
0 => 3,
1 => 7,
2 => 11,
3 => 15,
)
---
preferences:
108.69 ms | 408 KiB | 5 Q