我正在尝试从数组的子数组中获取图像并显示正确的大小。我已设法将子数组存储到变量中,但似乎无法抓取图像。 我想输出[media_url]和[thumb]尺寸。
这是通过print_r()输出的数组:
Array
(
[0] => stdClass Object
(
[id] => 81223091856078976
[id_str] => 81223091856078976
[indices] => Array
(
[0] => 0
[1] => 23
)
[media_url] => http://pbs.twimg.com/media/C0Wft4WEAACVt_.jpg
[media_url_https] => https://pbs.twimg.com/media/C0Wft4WEAACVt_.jpg
[url] => https://xxxxxxx.com
[display_url] => pic.twitter.com/xxxxxxx
[expanded_url] => https://twitter.com/xxxxxxx/status/8122309393021504/photo/1
[type] => photo
[sizes] => stdClass Object
(
[medium] => stdClass Object
(
[w] => 1108
[h] => 784
[resize] => fit
)
[thumb] => stdClass Object
(
[w] => 150
[h] => 150
[resize] => crop
)
[small] => stdClass Object
(
[w] => 680
[h] => 481
[resize] => fit
)
[large] => stdClass Object
(
[w] => 1108
[h] => 784
[resize] => fit
)
)
提前致谢
答案 0 :(得分:1)
你可以这样做: -
$arr[0]->media_url
$arr[0]->sizes->thumb->w
$arr[0]->sizes->thumb->h
$arr[0]->sizes->thumb->resize
注意: - 如果您使用的是foreach()
,请从所有人中删除[0]
。