0

我有一个需要循环的数组数组。这是示例:

Array ( [data] => Array ( [0] => Array ( [name] => Paul van Dyk @ Cream Amensia Opening Party, Ibiza [start_time] => 2013-06-13 [timezone] => Europe/Madrid [location] => Amnesia Ibiza [id] => 553728968001075 [rsvp_status] => attending ) [1] => Array ( [name] => Lskdjlkdsfj [start_time] => 2013-06-12 [timezone] => Europe/Rome [location] => Rome, Lazio [id] => 592087844156650 [rsvp_status] => attending ) [2] => Array ( [name] => Paul van Dyk @ Cream - BCM, Mallorca [start_time] => 2013-06-12 [timezone] => Europe/Madrid [location] => BCM Planet Dance [id] => 182367615251136 [rsvp_status] => unsure ) ) [paging] => Array ( [previous] => https://graph.facebook.com/100004042705860/events?limit=25&since=1371081600&__paging_token=553728968001075&__previous=1 [next] => https://graph.facebook.com/100004042705860/events?limit=25&until=1370995200&__paging_token=592087844156650,182367615251136 ) )

现在这就是我正在做的事情:我在数组中使用两个 foreach 循环并获取数据。问题是 [next] 和 [previous] 不包含在循环中,否则通过在变量中传递错误的值,结果会发生奇怪的事情。特别是变量 $fb_event_data['id'] 在最后两个循环中不会得到正确的值。

$fb_events = $facebook->api('/me/events/');
  foreach ($fb_events as $data) {
        foreach ($data as $fb_event_data) {
    $event_info = json_decode(file_get_contents('https://graph.facebook.com/'.$fb_event_data['id'].'/?access_token='.$fb_user_details['fb_token']));  

          echo $event_info->description."<br/>";
        }
    }
4

1 回答 1

0

您只想获取事件的数据键,所以使用它。

foreach ($fb_events["data"]  as $fb_event_data) {
    $event_info = json_decode(file_get_contents('https://graph.facebook.com/'.$fb_event_data['id'].'/?access_token='.$fb_user_details['fb_token']));  
    echo $event_info->description."<br/>";
}
于 2013-06-12T19:43:12.763 回答