这就是我的数组的样子。
(int) Year 1 => array(
'Department 1' => array(
'Sales' => '12345'
),
'Department 2' => array(
'Sales' => '12345'
),
),
(int) Year 2 => array(
'Department 1' => array(
'Sales' => '12345'
),
'Department 2' => array(
'Sales' => '12345'
),
)
我希望能够创建一个表,其中标题是 X 轴上的年份。Y 轴需要以部门名称开头。相邻的单元格需要在一个单元格中包含销售额、收入和总额。
它应该看起来像这样......
Department____| ___YEAR1_______ | __Year2
Department 1 |Sales [dept 1][year 1] | Sales[dept 1][year 2]
Department 2 |Sales [dept 2][year 1] | Sales [dept 2][year 2]
我使用了嵌套的 foreach 循环
foreach($List as $key=>$row) {
echo "<tr><td>".$key."</td>";
foreach($row as $key2=>$col){
echo "<td>" . 'Sales: '.round($col['sales'],2) ."</td>";
}
echo "</tr>";
}
echo "</table>"; ?>
但它在 x 轴上打印了部门名称,在 y 轴上打印了年份。如何在 x 轴上获得年份,在 y 轴上获得部门。