在一系列时间间隔中搜索当前时间
问题描述:
如何检查当前时间是否处于休息时间或不使用php?我需要下面的阵列中搜索如果例如当前时间是任何任何破在一系列时间间隔中搜索当前时间
$current = date('Y-m-d H:i:s');
Array
(
[0] => Array
(
[break] => 1
[start] => 2017-10-10 16:32:00
[end] => 2017-10-12 14:54:33
)
[1] => Array
(
[break] => 2
[start] => 2017-10-16 14:54:33
[end] => 2017-10-18 23:55:00
)
)
答
foreach ($items as $item) {
if ($item->start <= $current && $item->end >= $current) {
// Do stuff
}
}
或...的开始/结束日期之间
$items = array_filter($items, function($item) {
return ($item->start <= $current && $item->end >= $current);
});
'> && urfusion
https://*.com/questions/2113940/compare-given-date-with-today,应该对你有用 –