<?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);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`