2016-11-12 52 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

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