Hi, I am using the below if conditional to load differrent code based on the time of day.
I was looking for suggestions for a better way to code this ?
Based on the below i would end up with 6 if statements for each day of the week.
Thanks.
<?php
$today = date("n");
$hour = date("G");
$sun = 1;
$mon = 2;
$tue = 3;
$wed = 4;
$thu = 5;
$fri = 6;
$sat = 7;
$open_time = 9;
$close_time = 17;
if ($today == $mon && $hour >= $open_time && $hour <= $close_time) {
print "Monday page code";
}
else {
print "Closed code";
}
?>
I'have been working on doing it this way with a switch but i need advice on the best way to do this.
switch ($day_of_week) {
case ($day_of_week == 2 && $hour_of_day >= 9 && $hour_of_day <= 17);
print "Monday";
break;
}