<?php
function callApi($offset, $limit) {
static $array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
echo "called with $offset, $limit\n";
return json_encode([
'results' => array_slice($array, $offset, $limit),
'next' => array_key_last($array) >= $offset + $limit
]);
}
$offset = 0;
$limit = 5;
$result = [];
do {
$response = json_decode(callApi($offset, $limit), true);
array_push($result, ...$response['results']);
$offset += $limit;
} while (!empty($response['next']));
var_export($result);
- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- called with 0, 5
called with 5, 5
called with 10, 5
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
4 => 5,
5 => 6,
6 => 7,
7 => 8,
8 => 9,
9 => 10,
10 => 11,
11 => 12,
)
preferences:
79.23 ms | 402 KiB | 62 Q