Echo data in a three dimensional array

Here is my array:

Array
(
    [0] => Array
        (
            [name] => event_info
            [fql_result_set] => Array
                (
                    [0] => Array
                        (
                            [name] => 8fr at Mission
                            [description] => 
                            [start_time] => 1359770400
                            [end_time] => 1359781200
                            [pic_small] => http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yy/r/XcB-JGXohjk.png
                            [pic_big] => http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yn/r/5uwzdFmIMKQ.png
                            [eid] => 143042695846457
                            [venue] => Array
                                (
                                    [id] => 57444830184
                                )

                            [location] => Mission Bar + Tapas
                        )

                    [1] => Array
                        (
                            [name] => 8fr at Mission
                            [description] => 
                            [start_time] => 1362189600
                            [end_time] => 1362200400
                            [pic_small] => http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yy/r/XcB-JGXohjk.png
                            [pic_big] => http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yn/r/5uwzdFmIMKQ.png
                            [eid] => 115985141901382
                            [venue] => Array
                                (
                                    [id] => 57444830184
                                )

                            [location] => Mission Bar + Tapas
                        )

                )

        )

    [1] => Array
        (
            [name] => event_venue
            [fql_result_set] => Array
                (
                    [0] => Array
                        (
                            [name] => Mission Bar + Tapas
                            [username] => 
                            [page_id] => 57444830184
                            [location] => Array
                                (
                                    [street] => 438 North Street
                                    [city] => Pittsfield
                                    [state] => MA
                                    [country] => United States
                                    [zip] => 01201
                                    [latitude] => 42.45488011426
                                    [longitude] => -73.251895160061
                                )

                        )

                )

        )

)

The first section is a series of events (there are 2 events). The second is a series of venues (there is 1 venue). I am looking to write a foreach loop and then echo the the event info for each event and include the venue info that matches that event. For example:

Event Name: 8fr at Mission [img]
Address: Mission Bar + Tapas, 438 North Street, Pittsfield, MA

Are you assembling this array? Is it coming out of a predefined function?

No I’m not assembling it. It’s coming from Facebook, and they have their event venue information in a separate table from their event info and they use the venue id, so they give me what you see there. I can provide another example of array data if it’s helpful.

no, i understand the data, its just assembled poorly lol. You can do this two ways; pre-emptively rewriting the arrays, or filtering through them. Lets look at filtering through them.

Assuming that the array will not change order (IE: index 0 is always event_info and index 1 is always event_venue)


foreach($bigarray[0]['fql_result_set'] AS $event) {
  $target = $event['venue']['id'];
  $venue = array_pop(array_filter($bigarray[1]['fql_result_set'],function($item) use ($target) { return $item['page_id'] == $target; }));
  echo //Whatever you want to echo. $event is your event info, $venue is your venue.
}

This is so great. Thank you for putting your time to this.

Echoing out the data is a breeze. But there’s a new issue I wanted to ask about: When an event has no venue ID (because no event venue was given) I get a PHP notice for that index:

Notice: undefined index: id

Is there a way to test for this in the loop?

if(!isset($event[‘venue’][‘id’])) {

Thanks again, working perfectly.