我将数组分成块。我想问如何循环它们以便将每个块用作数组并打印它们的数据?这是到目前为止我的代码..
$chunks = array_chunk($newarray, 5, true);
foreach ($chunks as $index => $chunk) {
}
$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-..to 数组大小]
或与 foreach
foreach ($chunks as $index => $chunk)
foreach ($chunk as $key => $value)
print_r($index . $key . $value);