数组分批次处理

$listIds ='1,2,3,4,5,5,6,7,8,9';
$result = array_filter(array_values(array_unique(explode(',',$listIds))));

$batchNums=2;
$num =ceil(count($result)/$batchNums);
$index =0;
for ($i = 0; $i < $num; $i++) {
    $index = $i * $batchNums;
    $newData = array_slice($result, $index, $batchNums);
    print_r($newData);
}

你可能感兴趣的:(linux,运维,服务器)