时间:2021-07-01 10:21:17 帮助过:31人阅读
$arr = array(1,2,3,4,5,6,7,8);
for($i=0; $i$temp = array_slice($arr, $i, 4);
for($k=1; $k<=2; $k++){
echo 'start'.$k.'
';
foreach ($temp as $val) {
echo $val.'
';
}
echo 'end'.$k.'
';
}
}
$arr = array(1,2,3,4,5,6,7,8);
$n = 2; // 循环2次
$split = 4; // 4个为一个分组
echo '';';
response($arr, $n, $split);
echo '
function response($arr, $n, $split){
while(count($arr)>0){
$tmp = array_splice($arr, 0, $split);
for($i=0;$i<$n;$i++){
echo 'start'.($i+1)."\r\n";
echo implode("\r\n", $tmp)."\r\n";
echo 'end'.($i+1)."\r\n";
}
echo "----------------------------------------------------------\r\n";
}
}
start1
1
2
3
4
end1
start2
1
2
3
4
end2
----------------------------------------------------------
start1
5
6
7
8
end1
start2
5
6
7
8
end2