SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Echo data in a three dimensional array

    Here is my array:
    Code:
    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
    Last edited by ggeiger; Jan 18, 2013 at 13:24. Reason: typo

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Are you assembling this array? Is it coming out of a predefined function?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    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)
    PHP Code:
    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.

    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    if(!isset($event['venue']['id'])) {
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    if(!isset($event['venue']['id'])) {
    Thanks again, working perfectly.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •