我正在尝试找出如何基于比较过滤对象。
我得到了一个看起来像这样的对象,尽管有15个结果...
stdClass Object
(
[FlightInfoExResult] => stdClass Object
(
[next_offset] => 15
[flights] => Array
(
[0] => stdClass Object
(
[faFlightID] => SWA2078-1499232401-airline-0885
[ident] => SWA2078
[aircrafttype] => B738
[filed_ete] => 03:00:00
[filed_time] => 1499232401
[filed_departuretime] => 1499477700
[filed_airspeed_kts] => 423
[filed_airspeed_mach] =>
[filed_altitude] => 0
[route] =>
[actualdeparturetime] => 0
[estimatedarrivaltime] => 1499489100
[actualarrivaltime] => 0
[diverted] =>
[origin] => KPHX
[destination] => KMKE
[originName] => Phoenix Sky Harbor Intl
[originCity] => Phoenix, AZ
[destinationName] => General Mitchell Intl
我需要筛选这个对象,只返回[flights]
,其中[filed_departuretime]
在查询结果$time = strtotime($item['departure_time']);
的1小时内。
可以像这样进行操作:
abs($object->filed_departuretime - $time) <= 3600)
希望这一切都说得通,感谢您的帮助 :) 我不太懂array_filter是如何工作的,所以目前的代码是这样的...
//set flight identity
$ident = $item['airline'].$item['flight_number'];
$date = date('Y-m-d H:i:s');
$time = strtotime($item['departure_time']);
//get flightaware results
$flightAwareResult = FlightInfoEx($ident);
/*$flightResult = array_filter(
$flightAwareResult,
);*/