2016-11-12 53 views
0

我在谷歌看了几个小时,但没有找到我的问题上的任何信息。php数组时间过滤

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

我得到数组元素$,这里也有我写出来与大家从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)); 

回答

0

这是因为你的$elements是二维数组和time2是在第二维。你的周期也是无止境的循环。

你需要像

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

谢谢!它的工作完美:) –