php - 检查 PHP 时间(H :i:s) reside between two times(H:i:s)

标签 php

假设,

$at_time = '07:45:00';

$ranges = [
   ['start' => '09:00:00', 'end' => '17:00:00'],
   ['start' => '17:00:00', 'end' => '08:59:00']
];

现在我想检查 $ranges 是否包含 $at_time

最佳答案

我的 PHP 有点生疏,但请尝试以下方法:

$matches=Array();

foreach($ranges as $i=>$ikey){
    if(strtotime($ranges[$i]['start']) < strtotime($at_time) && strtotime($ranges[$i]['end']) > strtotime($at_time)){
         array_push($matches,$i);
    }
}

然后 $matches 将包含包含 $at_time 的所有范围的数组。

关于php - 检查 PHP 时间(H :i:s) reside between two times(H:i:s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18374323/

相关文章:

php - jquery 使搜索自动建议列表从下到上打开(相反方向)

php - 单个查询中的多个数据库是可能的吗?

PHP MYSQL Foreach 日期列表

javascript - 删除 SQL 数据库网页中的一行

php - 如何在 PHP 中转义#

php - PHP 未更新 SQL 数据库中的数据

在 PHP 生成的 JavaScript 中调用时,通过 heredoc 声明的 PHP 变量将无法正确解析

php - 'expiry_date' 我的 sql 查询中的未知列 'where clause'

php - MySQL 数据库中无法识别的 UTF8 立陶宛字符

PHP 和 MySQL : database not retriving data inside print