Facebook graph API loop through paging

Your code works for me, the only thing that I did is to make sure that count($data["data"]) > 0 before merging it with the existing information. So it looks like this:

//loop through pages to return all results
while(in_array("paging", $data) && array_key_exists("next", $data["paging"])) {
    $offset += $limit;
    $data = $facebook->api("$fid/events/?limit=$limit&offset=$offset", $params);
    // make sure we do not merge with an empty array
    if (count($data["data"]) > 0){
        $events_data = array_merge($events_data, $data["data"]);
    } else {
        // if the data entry is empty, we have reached the end, exit the while loop
        break;
    }
}}