3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
151.15 ms | 1630 KiB | 15 Q