I have an end point that I can send a GET request to and it returns a different result depending on the limit and offset.
https://example-foo-bar.com?l=100&o=0 // returns the first 100 items.
I want to create a for loop (or a Nested for loop I assume) that returns a 100 items at a time, adding the result to an array each time, until the end of the response. I have the code for sending the curl request and storing the result, just struggling on the batch processing part.
Something like:
https://example-foo-bar.com?l=100&o=0
https://example-foo-bar.com?l=100&o=99
https://example-foo-bar.com?l=100&o=199
https://example-foo-bar.com?l=100&o=218 // end of response ?
I also know how many result there are in total, stored as $count;
I ended up with something like this but it doesn't feel like the best practice:
function testLoop(){
$limit = 100;
$count = getCount();
$j = ceil($count/$limit);
for ($i = 0; $i < $j; $i++){
$offset = $i*100;
echo 'https://example-foo-bar?l='.$limit.'&o='.$offset.'';
}
}
testLoop();