PHP检查值是否在数组值内
我使用PHP检查开始时间和结束时间是否在数组开始时间和结束时间内,然后不显示这些时间戳。 像这样的PHP检查值是否在数组值内,php,loops,Php,Loops,我使用PHP检查开始时间和结束时间是否在数组开始时间和结束时间内,然后不显示这些时间戳。 像这样的 while ($row = mysql_fetch_assoc($getReservationSettings)) { if((strtotime($res_date) >=strtotime($row['start_date'])) && $row['recur_end_date'] == '0000-00-00') { if((17:00 <
while ($row = mysql_fetch_assoc($getReservationSettings)) {
if((strtotime($res_date) >=strtotime($row['start_date'])) && $row['recur_end_date'] == '0000-00-00')
{
if((17:00 <=$row['start_time']) || 17:00 >=$row['end_time'])
{
$myarray[]=date("H:i:s",strtotime($time)+$i*$secs);
}
}
}
while($row=mysql\u fetch\u assoc($getReservationSettings)){
如果((strotime($res\u date)>=strotime($row['start\u date'])和&$row['recur\u end\u date']=='0000-00-00')
{
如果((17:00=$row['end_time']))
{
$myarray[]=日期(“H:i:s”,strotime($time)+$i*$secs);
}
}
}
这里发生的事情是,在第一个循环中,如果开始时间是17:15,结束时间是18:00,它不会显示该范围内的时间。但是如果在第二个循环中,开始时间是13:15,结束时间是15:00,那么它将显示第一个循环中的时间。基本上,我必须通过每个循环验证它。请帮助我。谢谢数组的开始时间和结束时间,然后通过in_数组php函数找到所需的日期时间 例如:
<?php
$time= array("17:00", "18:00", "19:00", "20:00");
if (in_array("18:00", $time))
{
echo "Match found";
}
else
{
echo "Match not found";
}
?>
字符串不能小于或大于。您需要整数,或者在数据库中使用介于之间的执行此操作。请记住,mysql扩展已被弃用…我使用的是时间戳,而不是字符串。在数据库中使用时间数据类型。'17:00'
是字符串,而不是时间戳。抱歉,这是一个错误,问题与if状态无关这很好。我必须在每个循环中比较17:00。并且只显示那些不在if语句下的。这在我的情况下不起作用,因为时间是不确定的,并且有一个时间范围而不是间隔,我必须验证它。