Berisko
Berisko

Reputation: 643

PHP How to get data from multiple level array

I have this array from JSON file and I want to get data from [url]. Array is saved as variable $data.

stdClass Object
(
    [images] => Array
    (
            [0] => stdClass Object
            (
                    [startdate] => 20190625
                    [fullstartdate] => 201906250700
                    [enddate] => 20190626
                    [url] => /th?id=OHR.SutherlandFalls_ROW5711472757_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp
            )
    )
)

Result should be like:

echo $data[0]->url; will show the link/value /th?id=...

Upvotes: 1

Views: 32

Answers (1)

Chin Leung
Chin Leung

Reputation: 14921

Your $data variable is not an array, it's an instance of stdClass. Therefore, you can retrieve it like this:

$data->images[0]->url;

Upvotes: 1

Related Questions