Sergejs Jefremovs Sergejs Jefremovs - 11 months ago 70
PHP Question

php array time filtering

i looked in google for several hours, but did not find any info on my question.

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

i got array $elements, where i got written rows with code you see up from HTML table from page in internet. But i cant find the way, how can make filtering by time.

For example i want to use time interval 3 hours and get from array elements for next 3 hours.

I tried to use

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

echo information from array;


but he throws error:

[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

time stores in array with simple_dom:

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

Answer Source

It is because your $elements is two-dimensional array and time2 is in second dimension. Also your cycle is an endless loop.

You will need something like

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