Mob*_*Mob 1 php algorithm pagination cursor
我有一个可以是来自用户的任何大小的数组.
API的每个请求中的最大值大小为100(从0到99),用户可以 在自己的数组中拥有(它可能是64或137或......) 234个值,我想要的是得到前100个值,接下来的100个值,然后是存储在数组或字符串中的接下来的34个值.
就像是 ;
First Hundred : 0 - 99 //100
Second Hundred : 100 - 199 //100
Next Values : 200 - 234 //34
Run Code Online (Sandbox Code Playgroud)
在每个实例中,值都附加到字符串,如下所示.
$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;
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?我觉得这很容易,但我错过了一些东西.谢谢.
可以在此处找到json编码数组的样本
小智 5
您想使用array_chunk函数.
http://php.net/manual/en/function.array-chunk.php
$request_bits = array_chunk($notfm, 100)
foreach ($request_bits as $request_bit) {
...
}
Run Code Online (Sandbox Code Playgroud)
或者,你可以设置一个单独的条件来在计数器为100时发出请求,清空ID数组,并清空计数器,但除非内存管理是一个巨大的问题,否则array_chunk会做到这一点.