Question

{ "_embedded": { "events": [ { "name": "George Lopez", "type": "event", "id": "G5vYZ4m1ln0VG", "test": false, "url":...

{
  "_embedded": {
    "events": [
      {
        "name": "George Lopez",
        "type": "event",
        "id": "G5vYZ4m1ln0VG",
        "test": false,
        "url": "https://www.ticketmaster.com/george-lopez-santa-cruz-california-11-15-2019/event/1C0056E2ABAA4D0C",
        "locale": "en-us",
        "images": [
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_LARGE_16_9.jpg",
            "width": 2048,
            "height": 1152,
            "fallback": false
          },
          {
            "ratio": "4_3",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_CUSTOM.jpg",
            "width": 305,
            "height": 225,
            "fallback": false
          },
          {
            "ratio": "3_2",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_PORTRAIT_3_2.jpg",
            "width": 640,
            "height": 427,
            "fallback": false
          },
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_LANDSCAPE_16_9.jpg",
            "width": 1136,
            "height": 639,
            "fallback": false
          },
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_PORTRAIT_16_9.jpg",
            "width": 640,
            "height": 360,
            "fallback": false
          },
          {
            "ratio": "3_2",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_ARTIST_PAGE_3_2.jpg",
            "width": 305,
            "height": 203,
            "fallback": false
          },
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_EVENT_DETAIL_PAGE_16_9.jpg",
            "width": 205,
            "height": 115,
            "fallback": false
          },
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RECOMENDATION_16_9.jpg",
            "width": 100,
            "height": 56,
            "fallback": false
          },
          {
            "ratio": "3_2",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_3_2.jpg",
            "width": 1024,
            "height": 683,
            "fallback": false
          },
          {
            "ratio": "16_9",
            "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_16_9.jpg",
            "width": 1024,
            "height": 576,
            "fallback": false
          }
        ],
        "sales": {
          "public": {
            "startDateTime": "2019-07-12T17:00:00Z",
            "startTBD": false,
            "endDateTime": "2019-11-16T04:00:00Z"
          },
          "presales": [
            {
              "startDateTime": "2019-07-10T16:00:00Z",
              "endDateTime": "2019-07-12T17:00:00Z",
              "name": "SCW STH Presale"
            },
            {
              "startDateTime": "2019-07-10T18:00:00Z",
              "endDateTime": "2019-07-12T17:00:00Z",
              "name": "SCW Partner Presale"
            },
            {
              "startDateTime": "2019-07-10T20:00:00Z",
              "endDateTime": "2019-07-12T17:00:00Z",
              "name": "SCW Warriors Insider Presale"
            },
            {
              "startDateTime": "2019-07-10T22:00:00Z",
              "endDateTime": "2019-07-12T17:00:00Z",
              "name": "GSW Warriors Insider Presale"
            },
            {
              "startDateTime": "2019-07-11T17:00:00Z",
              "endDateTime": "2019-07-12T17:00:00Z",
              "name": "Catalyst Presale"
            }
          ]
        },
        "dates": {
          "start": {
            "localDate": "2019-11-15",
            "localTime": "19:00:00",
            "dateTime": "2019-11-16T03:00:00Z",
            "dateTBD": false,
            "dateTBA": false,
            "timeTBA": false,
            "noSpecificTime": false
          },
          "timezone": "America/Los_Angeles",
          "status": {
            "code": "onsale"
          },
          "spanMultipleDays": false
        },
        "classifications": [
          {
            "primary": true,
            "segment": {
              "id": "KZFzniwnSyZfZ7v7na",
              "name": "Arts & Theatre"
            },
            "genre": {
              "id": "KnvZfZ7vAe1",
              "name": "Comedy"
            },
            "subGenre": {
              "id": "KZazBEonSMnZfZ7vF17",
              "name": "Comedy"
            },
            "type": {
              "id": "KZAyXgnZfZ7v7nI",
              "name": "Undefined"
            },
            "subType": {
              "id": "KZFzBErXgnZfZ7v7lJ",
              "name": "Undefined"
            },
            "family": false
          }
        ],
        "promoter": {
          "id": "494",
          "name": "PROMOTED BY VENUE",
          "description": "PROMOTED BY VENUE / NTL / USA"
        },
        "promoters": [
          {
            "id": "494",
            "name": "PROMOTED BY VENUE",
            "description": "PROMOTED BY VENUE / NTL / USA"
          }
        ],
        "priceRanges": [
          {
            "type": "standard",
            "currency": "USD",
            "min": 50,
            "max": 80
          }
        ],
        "_links": {
          "self": {
            "href": "/discovery/v2/events/G5vYZ4m1ln0VG?locale=en-us"
          },
          "attractions": [
            {
              "href": "/discovery/v2/attractions/K8vZ9171i6f?locale=en-us"
            }
          ],
          "venues": [
            {
              "href": "/discovery/v2/venues/KovZ917AhZI?locale=en-us"
            }
          ]
        },
        "_embedded": {
          "venues": [
            {
              "name": "KAISER PERMANENTE ARENA",
              "type": "venue",
              "id": "KovZ917AhZI",
              "test": false,
              "url": "https://www.ticketmaster.com/kaiser-permanente-arena-tickets-santa-cruz/venue/230011",
              "locale": "en-us",
              "postalCode": "95060",
              "timezone": "America/Los_Angeles",
              "city": {
                "name": "Santa Cruz"
              },
              "state": {
                "name": "California",
                "stateCode": "CA"
              },
              "country": {
                "name": "United States Of America",
                "countryCode": "US"
              },
              "address": {
                "line1": "140 Front Street"
              },
              "location": {
                "longitude": "-122.023142",
                "latitude": "36.968313"
              },
              "markets": [
                {
                  "name": "N. California/N. Nevada",
                  "id": "41"
                }
              ],
              "dmas": [
                {
                  "id": 250
                },
                {
                  "id": 273
                },
                {
                  "id": 282
                },
                {
                  "id": 341
                },
                {
                  "id": 368
                },
                {
                  "id": 374
                },
                {
                  "id": 382
                }
              ],
              "boxOfficeInfo": {
                "openHoursDetail": "Arena Box Office is open 1.5 hours prior to Tipp-off",
                "acceptedPaymentDetail": "Visa, Mastercard, Discover, American Express, Cash",
                "willCallDetail": "The “Will Call†windows open 1.5 hours prior to tip-off of each home game. The “Will Call†windows are located at the Kaiser Permanente Box Office on the Front Street side of Kaiser Permanente Arena. Picture identification is required to pick up any tickets. Will Call does not have a phone number; it is only a drop off and pick up point for day of game tickets."
              },
              "parkingDetail": "Event-day parking will be available throughout Downtown during the entire season. The following lots are available for $5 All Day: - Soquel/Front Garage (601 Front Street) - River Front Garage (24 River Street) - Lot 5: Calvary Church Lot (538 Center Street) - Lot 8: Pearl Alley Lot (710 Cedar Street) - Lot 9: Elm Street Lot (120 Elm Street) - Cedar/Church Garage (119 Church Street)",
              "generalInfo": {
                "generalRule": "The following items are prohibited from Kaiser Permanente Arena. All items are subject to search: • Weapons of any kind • Bags larger than 14″ x 14″ x 6″ • Backpacks of any size • Outside food or beverages, including liquids of any kind • Hard-sided containers, including bottles, cans, flasks, cooler and thermoses • Illegal drugs • Electronic Cigarettes • Any size pole or stick • Fireworks • Artificial noisemakers of any kind • Projectiles, including inflatable balls and Frisbees • Still cameras w/lenses longer than 3″ • Video cameras • Laptop computers • Laser pointers • Large radios • Portable Chairs • Scooter, bicycles, roller-skates and skateboards • Strollers • Non-service animals • Inappropriate attire or signage • Any item deemed by Management to be dangerous, inappropriate or disruptive to other fans’ enjoyment of the event."
              },
              "upcomingEvents": {
                "_total": 1,
                "ticketmaster": 1
              },
              "_links": {
                "self": {
                  "href": "/discovery/v2/venues/KovZ917AhZI?locale=en-us"
                }
              }
            }
          ],
          "attractions": [
            {
              "name": "George Lopez",
              "type": "attraction",
              "id": "K8vZ9171i6f",
              "test": false,
              "url": "https://www.ticketmaster.com/george-lopez-tickets/artist/770234",
              "locale": "en-us",
              "externalLinks": {
                "musicbrainz": [
                  {
                    "id": "4a41c200-153b-4158-87b3-db0fea627e2c"
                  }
                ]
              },
              "images": [
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_LARGE_16_9.jpg",
                  "width": 2048,
                  "height": 1152,
                  "fallback": false
                },
                {
                  "ratio": "4_3",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_CUSTOM.jpg",
                  "width": 305,
                  "height": 225,
                  "fallback": false
                },
                {
                  "ratio": "3_2",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_PORTRAIT_3_2.jpg",
                  "width": 640,
                  "height": 427,
                  "fallback": false
                },
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_LANDSCAPE_16_9.jpg",
                  "width": 1136,
                  "height": 639,
                  "fallback": false
                },
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RETINA_PORTRAIT_16_9.jpg",
                  "width": 640,
                  "height": 360,
                  "fallback": false
                },
                {
                  "ratio": "3_2",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_ARTIST_PAGE_3_2.jpg",
                  "width": 305,
                  "height": 203,
                  "fallback": false
                },
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_EVENT_DETAIL_PAGE_16_9.jpg",
                  "width": 205,
                  "height": 115,
                  "fallback": false
                },
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_RECOMENDATION_16_9.jpg",
                  "width": 100,
                  "height": 56,
                  "fallback": false
                },
                {
                  "ratio": "3_2",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_3_2.jpg",
                  "width": 1024,
                  "height": 683,
                  "fallback": false
                },
                {
                  "ratio": "16_9",
                  "url": "https://s1.ticketm.net/dam/a/be1/1cd433f7-92bb-4890-8c24-cecd2135fbe1_576361_TABLET_LANDSCAPE_16_9.jpg",
                  "width": 1024,
                  "height": 576,
                  "fallback": false
                }
              ],
              "classifications": [
                {
                  "primary": true,
                  "segment": {
                    "id": "KZFzniwnSyZfZ7v7na",
                    "name": "Arts & Theatre"
                  },
                  "genre": {
                    "id": "KnvZfZ7vAe1",
                    "name": "Comedy"
                  },
                  "subGenre": {
                    "id": "KZazBEonSMnZfZ7vF17",
                    "name": "Comedy"
                  },
                  "type": {
                    "id": "KZAyXgnZfZ7v7nI",
                    "name": "Undefined"
                  },
                  "subType": {
                    "id": "KZFzBErXgnZfZ7v7lJ",
                    "name": "Undefined"
                  },
                  "family": false
                }
              ],
              "upcomingEvents": {
                "_total": 23,
                "tmr": 3,
                "ticketmaster": 20
              },
              "_links": {
                "self": {
                  "href": "/discovery/v2/attractions/K8vZ9171i6f?locale=en-us"
                }
              }
            }
          ]
        }
      },
    

Trying to parse the json with php and I'm having trouble using a for loop to access the name of the event and the name of the venue. Here is what I have now for the loop:

for ($i = 0; $i < count($data); $i++)
{
echo $data['_embedded']['events'][$i]['name'];
echo $data['_embedded']['events'][$i]['_embedded']['venues'][$i]['name'];
  
}

There is more to the json but the question is deemed too long. Just imagine there is more of the similar format above and that I would have to loop through all of them for the event and venue.

Homework Answers

Answer #1
for ($i = 0; $i < count($data['_embedded']['events']); $i++)
{
echo $data['_embedded']['events'][$i]['name'];
echo $data['_embedded']['events'][$i]['_embedded']['venues'][0]['name']; // Only taking the first venue
  
}

You should count on the array, not on the object.. Hence, $data['_embedded']['events'] is the array.. 

Similarly, Venues is again an array.. if you just want to use first venue for each event, then take venue at index 0, like i showed.. Else for all venues, you can again use a nested loop inside to print all the venues.

hope it helps!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions