I have an array which could be of any size coming from users.
The maximum size of values in each request to the API is 100 (from 0 – 99), a user could have ( it varies could be 64 or 137 or …. ) 234 values in his own array, what I want is to get the first hundred values, the next 100 values, then the next 34 values stored in an array or a string.
Something like ;
First Hundred : 0 - 99 //100
Second Hundred : 100 - 199 //100
Next Values : 200 - 234 //34
In each instance the values get appended to a string as seen below.
$lookupString = "";
//$notfm = one-dim array of values
for( $i = 0; $i <= 99; $i++ ){
$lookupString .= $notfm[$i].",";
}
$lookup = "http://api.lol.com/1/?user_ids=".$lookupString;
Can someone help me on this? I think this is easy but I’m missing something. Thanks.
Sample of the json encoded array can be found here
You want to use the array_chunk function.
http://php.net/manual/en/function.array-chunk.php
Alternately, you can set a separate condition to make the request when the counter is 100, empty the array of IDs, and empty the counter, but unless memory management is a huge issue array_chunk will do the trick.