I'm putting together some location pages. I'm trying to figure out the best way to group the hours if they are exactly the same.
Results before code below.
Mon 8:30 a.m. - 4:30 p.m.
Tues 8:30 a.m. - 4:30 p.m.
Wed 8:30 a.m. - 4:30 p.m.
Thur 8:30 a.m. - 4:30 p.m.
Fri 8:30 a.m. - 5:00 p.m.
Sat 8:00 a.m. - 12:00 p.m.
Sun Closed
Results after implementing code below.
Mon 8:30 a.m. - 4:30 p.m.
Fri 8:30 a.m. - 5:00 p.m.
Sat 8:00 a.m. - 12:00 p.m.
Sun Closed
Result I'm trying to achieve. Basically I need to append the last day of a grouped series. So, append Thursday after Monday. I'm hoping that this will also be dynamic. So if the groupings change it's smart enough to append the last day as needed.
Mon-Thur 8:30 a.m. - 4:30 p.m.
Fri 8:30 a.m. - 5:00 p.m.
Sat 8:00 a.m. - 12:00 p.m.
Sun Closed
This code does everything minus append the last day of a grouped series. After staring at for a few hours, I'm not sure this will work? I tried adding a second foreach loop to build the days that are causing the if statement below to trigger. Then using that new array to print the data. No luck though. Anyone wanna point me in a direction?
<?php
// Set the variables for open and close
$open = '';
$close = '';
foreach ($lobby as $key => $hours) {
// Check the open and close variables and if the same group by days of the week
if (($open != $hours['hours_open'] || $close != $hours['hours_close']) && $hours['hours_notopen'] != 'yes') {
echo '<dd>'.$days[$hours['hours_dayofweek']].'</dd>';
echo '<dd class="hours">'.ltrim($hours['hours_open'], '0'). ' a.m. - '.ltrim($hours['hours_close'], '0'). ' p.m.</dd>';
$open = $hours['hours_open'];
$close = $hours['hours_close'];
}
if ($hours['hours_notopen'] == 'yes') {
echo '<dd>'.$days[$hours['hours_dayofweek']].'</dd>';
echo '<dd>Closed</dd>';
}
?>
<?
}
?>