PHP-开放时间

PHP-开放时间,php,time,Php,Time,我正在尝试运行一个脚本,它将在营业时间显示一条消息,但在通宵工作时(如晚上11点至凌晨4点)它似乎不起作用,您知道我如何解决它吗?目前的代码如下: date_default_timezone_set('Etc/GMT+0'); // Define daily open hours. Must be in 24-hour format, separated by dash. If closed for the day, set to 00:00-00:00 $time_range_mon =

我正在尝试运行一个脚本,它将在营业时间显示一条消息,但在通宵工作时(如晚上11点至凌晨4点)它似乎不起作用,您知道我如何解决它吗?目前的代码如下:

date_default_timezone_set('Etc/GMT+0'); 

// Define daily open hours. Must be in 24-hour format, separated by dash. If closed for the day, set to 00:00-00:00
$time_range_mon = '23:00-04:00';
$time_range_tue = '23:00-04:00';
$time_range_wed = '23:00-04:00';
$time_range_thu = '23:00-04:00';
$time_range_fri = '23:00-04:00';
$time_range_sat = '23:00-04:00';
$time_range_sun = '23:00-04:00';

// Gets current day of week
$status_today = strtolower(date("D"));
// Gets current time of day in 00:00 format
$current_time = date("G:i");
// Makes current time of day computer-readable
$current_time_x = strtotime($current_time);

// Builds an array, assigning user-defined time ranges to each day of week
$all_days = array("mon" => $time_range_mon, "tue" => $time_range_tue, "wed" =>     $time_range_wed, "thu" => $time_range_thu, "fri" => $time_range_fri, "sat" =>     $time_range_sat, "sun" => $time_range_sun);
foreach ($all_days as &$each_day) {
    $each_day = explode("-", $each_day);
    $each_day[0] = strtotime($each_day[0]);
    $each_day[1] = strtotime($each_day[1]);
}

// Defines array of possible days of week
$week_days = array("mon", "tue", "wed", "thu", "fri", "sat", "sun");

// Compares current day of week to possible days of week and determines open vs closed     output based on current day and time.
foreach ($week_days as &$each_week_day) {
    if ($status_today == $each_week_day) {
        if (($all_days[$each_week_day][0] <= $current_time_x) &&     ($all_days[$each_week_day][1] >= $current_time_x)) {
        echo "Running Script - Operating Hours";
    } else {
        echo "Not Running Script - Out of Hours";
        }
    }
}

如果$status\u today==$every\u week\u day比较,为什么会很有趣?为什么不直接查找$all_days[$status_today][0]呢?过去几天,我一直很难让它通宵检查,这是一个在线示例的一个版本,我发现它会减少,这只是我试图通宵检查的一点,然后我会把它放回我的代码中,只是尝试让它工作,你认为改变这一点会解决问题吗?如果$status\u today===每周$u day比较,为什么会很有趣?为什么不直接查找$all_days[$status_today][0]呢?过去几天,我一直很难让它通宵检查,这是一个在线示例的一个版本,我发现它会减少,这只是我试图通宵检查的一点,然后我会把它放回我的代码中,只是尝试让它工作,你认为改变这一点能解决问题吗?