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?