Note that this is similar to Processing Multidimensional JSON Array with PHP, only with one caviot.
I have a JSON with a few arrays from the following taken from Airtable (URLs censored)
{
"records": [
{
"id": "RECORD_ID",
"fields": {
"Name": "Setsuna Meioh",
"Birthday": "2020-10-29",
"Gender": "Female",
"Series": "Sailor Moon",
"Picture": [
{
"id": "this_is_id1",
"url": "http://IMAGE.URL",
"filename": "IMAGE_FILENAME",
"size": 97060,
"type": "image/png",
"thumbnails": {
"small": {
"url": "https://dl.airtable.com/THUMBNAIL_SMAL_URL",
"width": 34,
"height": 36
},
"large": {
"url": "https://dl.airtable.com/THUMBNAIL_LARGE_URL",
"width": 295,
"height": 317
},
"full": {
"url": "https://dl.airtable.com/THUMBNAIL_FULL_URL",
"width": 3000,
"height": 3000
}
}
}
]
}
},
{
"id": "RECORD_ID2",
"fields": {
"Name": "Rin Hoshizora",
"Birthday": "2020-11-01",
"Gender": "Female",
"Series": "Love Live (School Idol Project)",
"Picture": [
{
"id": "this_is_id2",
"url": "http://IMAGE.URL",
"filename": "IMAGE_FILENAME",
"size": 131749,
"type": "image/png",
"thumbnails": {
"small": {
"url": "https://dl.airtable.com/THUMBNAIL_SMAL_URL",
"width": 34,
"height": 36
},
"large": {
"url": "https://dl.airtable.com/THUMBNAIL_LARGE_URL",
"width": 295,
"height": 317
},
"full": {
"url": "https://dl.airtable.com/THUMBNAIL_FULL_URL",
"width": 3000,
"height": 3000
}
}
}
]
}
}
]
}
I'm trying to access the url item in a Picture array, and I already have the jsonDecode method already set up from a cURL response.
Now, I already know how to use the brackets [] when it's accessing a array (as shown on the link above), but the problem is, there is another array in a array.
What I did was using a longer string to get to a array.
echo $data->records[0]->fields->Picture[0]->thumbnails->small->url;
I tried that, but unfortunately came out nothing. Then I tried another method below
$Image1Base = $data->records[0]->fields->Picture[0];
$Image1URL = $Image1Base->url;
// then the echo
echo $Image1URL
Came out nothing either. Is there something missing?
json_decodeto true to get an associative array. It will be much easier for you. See php.net/manual/en/function.json-decode.php