I have an API which returns the following data from NBA matches, here is a JSON snippet from a single game.
{
"league": {
"id": "4353138d-4c22-4396-95d8-5f587d2df25c",
"name": "NBA",
"alias": "NBA"
},
"season": {
"id": "86a687a8-74fa-4c31-92a7-40498d3f3d8b",
"year": 2018,
"type": "PRE"
},
"games": [{
"id": "feb73ae6-39e6-4613-94f3-37eca10515a0",
"status": "closed",
"coverage": "full",
"scheduled": "2018-09-28T23:00:00+00:00",
"home_points": 104,
"away_points": 84,
"track_on_court": true,
"reference": "0011800001",
"time_zones": {
"venue": "US/Eastern",
"home": "US/Eastern"
},
"venue": {
"id": "b3dca541-859e-5301-bf90-4ec677a514a9",
"name": "Wells Fargo Center",
"capacity": 20478,
"address": "3601 S. Broad Street",
"city": "Philadelphia",
"state": "PA",
"zip": "19148",
"country": "USA",
"sr_id": "sr:venue:6068"
},
"broadcasts": [{
"network": "NBCS-PH+",
"type": "TV",
"locale": "Home"
}],
"home": {
"name": "Philadelphia 76ers",
"alias": "PHI",
"id": "583ec87d-fb46-11e1-82cb-f4ce4684ea4c",
"sr_id": "sr:team:3420",
"reference": "1610612755"
},
"away": {
"name": "Melbourne United",
"alias": "MEL",
"id": "3bf4047b-ef03-42d4-848e-84bc7307958d"
}
},
Now I know I can get all the details from the games
array by doing the following:
MY CODE
$data = json_decode(file_get_contents('http:test.com'), true);
$games_array = $data['games'];
foreach ($games_array as $game) {
echo $game['scheduled'];
}
I can access any data from games
array by simply inserting the index into the $game[]
array
Example output from code above
2018-09-28T23:00:00+00:00
2018-09-28T23:30:00+00:00
My Question
How do I access data / indexes from the venue
array and the home
and away
arrays? As I see it they are all nested within the games
array. Any help appreciated.