I've worked with arrays in the past with PHP, but generally simple associative arrays that are easy to manage and crawl.
I am making an HTTP POST request to an API endpoint that returns a lot of data in JSON format. I'm using json_decode($response, true) to convert the json into an array, and am trying to access components of the array without luck - just serving me a blank page. Alternatively, if I do print_r on the array I just get a jumble of data, so I know at least the API is returning data.
Here's a snippet of the response from the API
{
"data": {
"accounts": [
{
"locations": [
{
"name": "Test Location",
"soundZones": [
{
"name": "Main",
"nowPlaying": {
"startedAt": "2017-09-06T00:38:51.000Z",
"track": {
"name": "Some Song Name 123",
"imageUrl": "https://some-cdn-url.com",
"Uri": "5hXEcqQhEjfZdbIZLO8mf2",
"durationMs": 327000,
"artists": [
{
"name": "SomeName",
"Uri": "5lpH0xAS4fVfLkACg9DAuM"
}
]
}
}
}
]
},
How would I use PHP to access, let's say, the NAME value under the track object? (In this example I'd be trying to return the value "Some Song Name 123")
Here's the code I'm using.. I know I'm way off
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$response = json_decode($response, true);
print_r($response[0]);