PHP如何从多级数组中获取数据

时间:2019-06-25 17:23:07

标签: php json

我有一个来自JSON文件的数组,我想从 [url] 获取数据。数组另存为变量$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
            )
    )
)

结果应类似于:

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

1 个答案:

答案 0 :(得分:1)

您的$data变量不是数组,而是stdClass的实例。因此,您可以像这样检索它:

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