0

I have been working with parsing some remote JSON with PHP. I have been able to download the JSON and assign it to a variable, and I have used the array functionality with json_decode:

$data = json_decode($remotejson, true);

I have then printed the complete array back to verify the contents of the array:

echo print_r($data);

The array prints back and I can see the keys and values:

[files] => Array
    (
        [/photogalleryupload.thumbs/1934307_000001.jpg] => Array
            (
                [source] => derivative
                [format] => Thumbnail
                [original] => moviefile_1934307.mp4
            )

I am trying to get the value of the first nested key name which is "/photogalleryupload.thumbs/1934307_000001.jpg" and assign it to a variable.

For example, I would like the following code:

echo $data['files'][0];

To return this:

/photogalleryupload.thumbs/1934307_000001.jpg

This does not work.

The difficulty I am having is that this value I am trying to return is a 2nd level key name and I have been having trouble finding a way of assigning it to a variable.

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0
$keys = array_keys($data['files'])
$key = $keys[0]
fsw
  • 3,595
  • 3
  • 20
  • 34