这可能很容易,但我已经有一段时间了,我似乎无法解决这个问题。
我有一个类,我可以在php中执行print_r($ return-> stream),我得到这个数组
[array] => stdClass Object
(
[_id] => 12299116736
[game] => League of Legends
[viewers] => 8520
[created_at] => 2014-12-23T00:38:18Z
[_links] => stdClass Object
(
[self] => https://api.twitch.tv/kraken/streams/trick2g
)
[preview] => stdClass Object
(
[small] => http://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-80x45.jpg
[medium] => http://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-320x180.jpg
[large] => http://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-640x360.jpg
[template] => http://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-{width}x{height}.jpg
)
[channel] => stdClass Object
(
[_links] => stdClass Object
(
[self] => http://api.twitch.tv/kraken/channels/trick2g
[follows] => http://api.twitch.tv/kraken/channels/trick2g/follows
[commercial] => http://api.twitch.tv/kraken/channels/trick2g/commercial
[stream_key] => http://api.twitch.tv/kraken/channels/trick2g/stream_key
[chat] => http://api.twitch.tv/kraken/chat/trick2g
[features] => http://api.twitch.tv/kraken/channels/trick2g/features
[subscriptions] => http://api.twitch.tv/kraken/channels/trick2g/subscriptions
[editors] => http://api.twitch.tv/kraken/channels/trick2g/editors
[videos] => http://api.twitch.tv/kraken/channels/trick2g/videos
[teams] => http://api.twitch.tv/kraken/channels/trick2g/teams
)
[background] =>
[banner] => http://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-channel_header_image-a712bd1af57ae2ee-640x125.jpeg
[broadcaster_language] => en
[display_name] => Trick2g
[game] => League of Legends
[logo] => http://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-profile_image-49f3cee5732742ee-300x300.jpeg
[mature] => 1
[status] => Godyr Gates > Godyr Devourer | Learn what not to do | 600,000 Soon | Xmas 24hour Kappa Lets go!
[partner] => 1
[url] => http://www.twitch.tv/trick2g
[video_banner] => http://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-channel_offline_image-14cb5e9c1e344836-640x360.png
[_id] => 28036688
[name] => trick2g
[created_at] => 2012-02-06T21:16:52Z
[updated_at] => 2014-12-23T09:42:35Z
[delay] => 0
[followers] => 598315
[profile_banner] => http://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-profile_banner-d326186fdd09f433-480.jpeg
[profile_banner_background_color] => #030303
[views] => 76721348
[language] => en
)
)
我试图将“预览 - >小”变成变量,但我似乎无法弄明白。
答案 0 :(得分:1)
简单地说,
echo $array->preview->small;
$array
是主阵列。
preview
是对象。
和
在该对象中,有一个属性small