我有一个这样的数组:
Array
(
[0] => Array
(
[date] => 2012-11-29
[description] => Work Done
[hours] => 1.0
[id] => 6502
[person-id] => 8853
[project-id] => 8928
[todo-item-id] => 122353
[person-name] => Jane Doe
)
[1] => Array
(
[date] => 2012-11-29
[description] => Work Done 2
[hours] => 1.0
[id] => 6502
[person-id] => 8853
[project-id] => 8928
[todo-item-id] => 122353
[person-name] => Jane Doe
)
[2] => Array
(
[date] => 2012-11-28
[description] => Work Done 3
[hours] => 1.0
[id] => 6502
[person-id] => 8853
[project-id] => 8928
[todo-item-id] => 122353
[person-name] => Jane Doe
)
等等。
我想在按日期分组的表格中显示此信息。我正在使用 foreach 来获取每个值,但我试图弄清楚如何检查每个数组中的日期是否相同,如果是,则只回显一次日期。这就是我到目前为止所得到的......
<table>
<tbody>
<?php
foreach($time as $log){
//tried this but it doesn't work
//if(array_unique($log['date'])){
echo '<thead>
<tr class="info">
<td colspan="3">'.$log[date].'</td>
</tr>
</thead>';
//};
echo "<tr>";
echo "<td>{$log['todo-item-id']}</td>";
echo "<td>{$log['description']}</td>";
echo "<td>{$log['hours']}</td>";
echo "</tr>";
} ?>
</tbody>
</table>