Php 如何从两个表列中的单个数组中输出每周开放时间
我有一个具有以下数组结构的数组(以$openingHours为单位),用于保存开始和结束时间的数据。对于每个品牌,可能有14个开放时间(尽管有些品牌可能只有7个开放时间,持续7天)[小时类型1或小时类型2]Php 如何从两个表列中的单个数组中输出每周开放时间,php,arrays,html-table,Php,Arrays,Html Table,我有一个具有以下数组结构的数组(以$openingHours为单位),用于保存开始和结束时间的数据。对于每个品牌,可能有14个开放时间(尽管有些品牌可能只有7个开放时间,持续7天)[小时类型1或小时类型2] Array ( [0] => Array ( [day] => Mon [open_time] => 08:30:00 [close_time] => 19:00:00
Array
(
[0] => Array
(
[day] => Mon
[open_time] => 08:30:00
[close_time] => 19:00:00
[hour_type] => 1
[brand_id] => 4
)
[7] => Array
(
[day] => Mon
[open_time] => 08:00:00
[close_time] => 18:00:00
[hour_type] => 2
[brand_id] => 4
)
)
我试图将其输出到以下结构的表中:
<div class="table">
<div class="thead">
<div class="tr">
<div class="th">Day</div>
<div class="th">Type 1</div>
<div class="th">Type 2</div>
</div>
</div>
<div class="tbody">
<div class="tr">
<?php
foreach($openingHours as $openingHour) {
// Check opening hour brand id against the parent brand id to display
// opening hours just for the correct brand
if ($openingHour['$brand_id'] == $brand['brand_id']) {
echo "<div class='td'>" . $openingHour["day"]. "</div>";
if ($openingHour['hour_type'] == 1){
echo "<div class='td'>" . $openingHour["open_time"] . "-" . $openingHour["close_time"] . "</div>";
}
if ($openingHour['hour_type'] == 2){
echo "<div class='td'>" . $openingHour["open_time"] . "-" . $openingHour["close_time"] . "</div>";
}
echo "</div><div class='tr'>";
}
}
?>
</div>
</div>
白天
类型1
类型2
请注意,您正在为模拟表的div分配类,这里有什么理由不使用经典的html表吗,由于您试图显示的数据是表格格式的?主要是因为我们试图在任何地方都不使用任何html表格,特别是因为我们不确定布局将如何,因此,如果我们使用的是不太表格格式的布局,则重写会少一点,但就最初的问题而言,即使使用经典html表格,问题仍然存在。