-1

これを 3 次元配列として持っている場合:

(int) Year 1 => array(
    'Department 1' => array(
        'Sales' => '12345',
        'Revenue' => '12345',
        'total' => '12345'
    ),
    'Department 2' => array(
        'Sales' => '12345',
        'Revenue' => '12345',
        'total' => '12345'
    ),
),
(int) Year 2 => array(
    'Department 1' => array(
        'Sales' => '12345',
        'Revenue' => '12345',
        'total' => '12345'
    ),
    'Department 2' => array(
        'Sales' => '12345',
        'Revenue' => '12345',
        'total' => '12345'
    ),

)

これを HTML テーブルに表示するにはどうすればよいでしょうか。年をヘッダーとして使用します。各行の先頭の左側に部門。AAnd Sales、Rev、および Total は、年列内の別の列に表示されます。

出力は次のようになります

Department_______YEAR1_________Year2

Department 1  |Sales,Reveue |Sales,Reveue
Department 2  |Sales,Reveue |Sales,Reveue
4

1 に答える 1

-1

まず、テーブルを作成しTH、ループの外に出す必要があります

<table>
<tr>
<th>Department</th>
<th>Year 1</th>
<th>Year 2</th>
</tr>
<tr>
<?php

foreach ($1stvalue as $first => $2ndvalue ) {
    foreach ($2ndvalue as $second => $3rdvalue) {
        foreach ($3rdvalue as $third) {   
            echo "<td>".$first."</td>"."<td>".$second."</td>"."<td>".$third."</td>"."</tr>";
        }
    }
}
?>

各次元をforeachループし、すべて取得したらエコーする必要があります

于 2013-10-17T17:51:54.097 に答える