尝试比较这两个数组,因此清除$ arr中的日期列表,仅显示$ schedule_1上显示的日期。但它正在输出array(),我无法弄清楚为什么!
// GENERATE DATE AND TIME ARRAY
// Set timezone
date_default_timezone_set('America/New_York');
// Start date
$date = date('Y-m-d H:') . "00";
// End date
$end_date = date ("Y-m-d H:i", strtotime("+1 week", strtotime($date)));
while (strtotime($date) <= strtotime($end_date)) {
$arr[] = "$date";
$date = date ("Y-m-d H:i", strtotime("+30 minutes", strtotime($date)));
}
// #1 SCHEDULE
$schedule_1 = array(
"2017-11-14 12:00:00",
"2017-11-14 13:00:00"
);
print_r(array_intersect($arr, $schedule_1));
答案 0 :(得分:1)
您所要做的就是:
$schedule_1 = array(
'date1' => "2017-11-14 12:00",
'date2' => "2017-11-14 13:00"
);
或者,下面的代码也可以解决您的问题:
$end_date = date ("Y-m-d H:i:s", strtotime("+1 week", strtotime($date)));
while (strtotime($date) <= strtotime($end_date)) {
$arr[] = "$date";
$date = date ("Y-m-d H:i:s", strtotime("+30 minutes", strtotime($date)));
}