我有这样的数组
Array
(
[0] => Array
(
[kode_mk] => KD.32021
[nama_mk] => Matematika Ekonomi
[semester] => 1
[jum_sks] => 3
[nilai] => A
)
[1] => Array
(
[kode_mk] => KD.32022
[nama_mk] => Teori Ekonomi Mikro
[semester] => 2
[jum_sks] => 2
[nilai] =>
)
[2] => Array
(
[kode_mk] => KD.32040
[nama_mk] => Teori Ekonomi Mikro
[semester] => 3
[jum_sks] => 2
[nilai] =>
)
[3] => Array
(
[kode_mk] => KD.32051
[nama_mk] => Dasar Akuntansi I
[semester] => 1
[jum_sks] => 3
[nilai] =>
)
[4] => Array
(
[kode_mk] => KD.32052
[nama_mk] => Dasar Akuntansi Lanjutan
[semester] => 2
[jum_sks] => 3
[nilai] =>
)
[5] => Array
(
[kode_mk] => KD.32060
[nama_mk] => Akuntansi Perbankan
[semester] => 4
[jum_sks] => 3
[nilai] =>
)
)
如何将它们分成两个数组并将它们循环到两个html表中??
答案 0 :(得分:2)
为什么不使用函数array_chunk?
将数组块化为具有大小元素的数组。最后一块可能 包含小于元素的元素。
$mySplitArray = array_chunk($array, 3);
var_dump($mySplitArray);
答案 1 :(得分:1)
使用foreach()
foreach($parentArray as $parent)
{
foreach($parent as $child)
{
echo '<table>';
echo '<tr>';
echo '<td> ' . $child['kode_mk'] . ' </td>';
echo '<td> ' . $child['nama_mk'] . ' </td>';
.
.
.
}
}
答案 2 :(得分:0)
我不是100%清楚“你分成两个阵列”是什么意思,但是我会在这里做什么:
foreach ($array as $row) {
//Start of table row
foreach($row as $key => $value) {
//work with keys/values
}
}