php total,php:total的某些块循环,然后rest

我不确定我做的是否正确:

我有很多东西,比如说624件。我想做一个循环,发送7个请求,前6个超过100个项目,最后一个超过24个。

所以我做了一些数学运算,找出我要经历多少个循环。

// this is the total number of items

$total = $result['total_items'];

// if we split the total into such chunks

$chunksize = 50;

// we will get a rest of so many items

$rest = $total % $chunksize;

// so including the query for the rest, we will have to repeat the query so many times

$queries_no = (($total-$rest)/$chunksize)+1;

上面的感觉有点笨拙。这条路对吗?

PS:之后,我可以重复查询必要的次数。

// prep loop

$i = 0;

$requested = 0;

$subscribers = [];

while ($i <= $queries_no){

// last item

if($i == $queries_no){

$chunksize = $rest;

}

$result = $this->monkeyApp->get('lists/'.$list_id.'/members?offset='.$requested.'&count='.$chunksize);

$subscribers = array_merge($subscribers,$result['members']);

$requested = $requested + $chunksize;

$i++;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值