【问题标题】:php array time filteringphp数组时间过滤
【发布时间】:2016-11-12 18:38:49
【问题描述】:

我在谷歌上搜索了几个小时,但没有找到关于我的问题的任何信息。

$elements[] = array('time1' => $time1, 'time2' => $time2, 'string1' => $string1, 'string2' => $string2, 'string3' => $string3, 'string4' => $string4);

我得到了数组 $elements,在那里我用你从 Internet 页面的 HTML 表中看到的代码编写了行。但是我找不到路,怎么能按时间过滤。

例如,我想使用 3 小时的时间间隔,并在接下来的 3 小时内从数组元素中获取。

我尝试使用

while( $tmnw = date("H:i", strtotime('+3 hours'));  $tmnw < $elements['time2'] ) {

echo information from array;

}

但他抛出错误:

[12-Nov-2016 20:35:03] PHP Notice:  Trying to get property of non-object in filtering.php on line 15
[12-Nov-2016 20:35:03] PHP Notice:  Undefined index: time2 in filtering.php on line 41

使用 simple_dom 将时间存储在数组中:

$time1= date( "H:i", strtotime( $row->find('td',0)->plaintext ) );
$time2= date( "H:i", strtotime( $row->find('td',1)->plaintext ) );

【问题讨论】:

    标签: php arrays time filtering


    【解决方案1】:

    这是因为您的$elements 是二维数组,而time2 是第二维。你的循环也是一个无限循环。

    你需要类似的东西

    $tmnw = date("H:i", strtotime('+3 hours'));
    foreach ($elements as $element) {
        if ($tmnw < $element['time2']) {
            echo 'info';
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-22
      • 2017-09-01
      • 2018-05-04
      • 2018-11-01
      • 1970-01-01
      • 2016-07-05
      • 2016-05-24
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多