It seems to me that I should use in_array () , but for some reason it gives me inaccurate information. I looked through array_search () and array_key_exists () , but it seems like this is only useful if I have a key and a value in my array that I am not doing. In a nutshell Im working condition to get the current time and day of EST and determine whether it is "within hours" or "after a few hours."
So, on Tuesday at 19:00 it should say "After an hour," but it repeats, "At hours," am I missing something?
Code example:
<?php
date_default_timezone_set('US/Eastern');
$current_time = date('A');
$current_day = date('l');
$current_hour = date('H');
$closed_days = array('Saturday','Sunday');
$closed_hours = array('17','18','19','20','21','22','23','00','01','02','03','04','05','06','07','08');
?>
<?php
echo $current_time . '<br />';
echo $current_day . '<br />';
echo $current_hour . '<br />';
if(!in_array($current_day, $closed_days) || !in_array($current_hour, $closed_hours)) {
echo 'During Hours';
} else {
echo 'After Hours';
} ?>
Returns:
PM
Tuesday
19
During Hours
Derek source
share