-4

我有这样的数组

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 表...?

4

3 回答 3

2

为什么不使用函数array_chunk

将数组分块为具有 size 元素的数组。最后一个块可能包含小于 size 的元素。

$mySplitArray = array_chunk($array, 3);
var_dump($mySplitArray);
于 2013-11-12T12:53:04.433 回答
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>';
        .
        .
        .
    }
}
于 2013-11-12T12:54:40.297 回答
0

我不是 100% 清楚你对“分成两个数组”的意思,但我会在这里做什么:

foreach ($array as $row) {
    //Start of table row
    foreach($row as $key => $value) {
        //work with keys/values
    }
}
于 2013-11-12T12:55:47.583 回答