gpt4 book ai didi

如果时间段已被占用,则 PHP 检查数组

转载 作者:行者123 更新时间:2023-11-28 23:47:06 33 4
gpt4 key购买 nike

如何检查开始到结束范围内的某个时间段是否已被占用。

我突出显示了问题(图片)。

  1. 时间段:00:00 - 00:45
  2. 时间段:03:00 - 06:00
  3. 时间段:05:00 - 10:00(这应该检查它是否必须大于 06:00)

HTML 标记

 #option value: 00:00 till 23:45 with 15 minutes gaps
<select name="start_time[]"></select>
<select name="finish_time[]"></select>

PHP:

if ( is_array($_POST['start_time']) ) {

$json_combine = array_combine($_POST['start_time'], $_POST['finish_time']);

foreach ($json_combine as $jcs => $jcf ) {
if ( ($jcs > $jcf) OR ($jcs == $jcf) ) {
echo 'Start time must before finish time.';
break;
}
}

}

enter image description here

最佳答案

也许您可以使用 DateTime 进行比较:

if ( is_array($_POST['start_time']) ) {
$json_combine = array_combine($_POST['start_time'], $_POST['finish_time']);

foreach ($json_combine as $jcs => $jcf ) {
$d1=new DateTime($jcs);
$d2=new DateTime($jcf);
if ($d1 >= $d2) {
echo 'Start time must before finish time.';
break;
}
}
}

关于如果时间段已被占用,则 PHP 检查数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434741/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com