我将数组分成了块。我想问一下如何循环使用它们以便将每个块用作数组并打印它们的数据?这是我到目前为止的代码..
$chunks = array_chunk($newarray, 5, true);
foreach ($chunks as $index => $chunk) {
}
答案 0 :(得分:1)
$chunks = array_chunk($newarray, 5, true);
for($i=0; $i<count($chunks);$i++){
for($n=0;$n<count($chunks[$i]);$n++){//or $n=0;$n<5;$n++ in your example
print_r($chunks[$i][$n]);
}
}
array_chunk默认索引所有块[0 - ..到数组大小]
或与foreach
foreach ($chunks as $index->$chunk)
foreach($chunk as $key->$value)
print_r($index.$key.$value);