-1

如果我将其作为一个三维数组:

(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 表格中显示它。以年为标题。各行开头左侧的部门。以及年列中单独列中的销售额、修订和总计。

输出应该看起来像

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>";
        }
    }
}
?>

你需要循环每个维度并在你得到它时回显它

于 2013-10-17T17:51:54.097 回答