dotn30471 2015-09-02 17:20
浏览 6

如何从两个表列中的单个数组输出每周开放时间

I have an array with the following array structure (for $openingHours) that holds the data for opening and closing hours. For each brand there could be a possible 14 (although some may just have 7 for seven days) opening times [Hour Type 1 or Hour Type 2].

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
        )
)

I am trying to output this into a table of the following structure:

<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>

But the above code simply outputs the hours for 'Type 1' and 'Type 2' Hour in the first . What am I missing here and I wonder if there is a 'better' way to achieve this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?