我需要制作一个表格来显示不同站点的评估分数,但并非每个站点都有每个月的数据。如何将数据放入正确的月份列,然后在没有数据的地方显示空白单元格?
这是一个示例数组:
Array
(
[Site 1] => Array
(
[1] => 89
[3] => 84
[4] => 96
[6] => 91
[8] => 90
[12] => 99
)
[Site 2] => Array
(
[1] => 90
[3] => 93
[4] => 88
)
[Site 3] => Array
(
[1] => 92
[3] => 92
[4] => 89
[6] => 94
[8] => 86
)
[Site 4] => Array
(
[1] => 93
[2] => 88
[3] => 92
[4] => 89
[5] => 93
[6] => 94
[8] => 90
[12] => 91
)
)
这就是我对 php.ini 的了解。我知道 for 循环有问题,但我不知道该怎么做。任何帮助表示赞赏。
echo "<table width='100%' border='1'>";
echo "<tr><th>Sites</th><th>Jan</th><th>Feb</th><th>Mar</th><th>Apr</th><th>May</th><th>Jun</th><th>Jul</th><th>Aug</th><th>Sep</th><th>Oct</th><th>Nov</th><th>Dec</th>";
foreach($report as $site=>$array)
{
echo "<tr><td>$site</td>";
foreach($array as $month=>$score)
{
for($i=1;$i<=12;$i++)
{
if($month==$i)
{
echo "<td>$score</td>";
}
else
{
echo "<td> </td>";
}
}
}
echo "</tr>";
}
echo "</table>";