我想从twitter获取当前趋势主题,所以我正在使用他们的api检索列表并返回一个多维数组。
有没有人知道如何解析这个?我想把名字放回变量中。提前谢谢!
Array
(
[0] => stdClass Object
(
[trends] => Array
(
[0] => stdClass Object
(
[name] => Mikhail Kalashnikov
[url] => http://twitter.com/search?q=%22Mikhail+Kalashnikov%22
[promoted_content] =>
[query] => %22Mikhail+Kalashnikov%22
[events] =>
)
[1] => stdClass Object
(
[name] => #YolsuzlukLobisi
[url] => http://twitter.com/search?q=%23YolsuzlukLobisi
[promoted_content] =>
[query] => %23YolsuzlukLobisi
[events] =>
)
[2] => stdClass Object
(
[name] => #DEMIin2013
[url] => http://twitter.com/search?q=%23DEMIin2013
[promoted_content] =>
[query] => %23DEMIin2013
[events] =>
)
[3] => stdClass Object
(
[name] => #GüzelPaylaşımlarİçinTakipleşelim
[url] => http://twitter.com/search?q=%23G%C3%BCzelPayla%C5%9F%C4%B1mlar%C4%B0%C3%A7inTakiple%C5%9Felim
[promoted_content] =>
[query] => %23G%C3%BCzelPayla%C5%9F%C4%B1mlar%C4%B0%C3%A7inTakiple%C5%9Felim
[events] =>
)
[4] => stdClass Object
(
[name] => #AÅŸkaÄ°nanmaz
[url] => http://twitter.com/search?q=%23A%C5%9Fka%C4%B0nanmaz
[promoted_content] =>
[query] => %23A%C5%9Fka%C4%B0nanmaz
[events] =>
)
[5] => stdClass Object
(
[name] => #AAPCON
[url] => http://twitter.com/search?q=%23AAPCON
[promoted_content] =>
[query] => %23AAPCON
[events] =>
)
[6] => stdClass Object
(
[name] => Micah Hyde
[url] => http://twitter.com/search?q=%22Micah+Hyde%22
[promoted_content] =>
[query] => %22Micah+Hyde%22
[events] =>
)
[7] => stdClass Object
(
[name] => Merry Christmas
[url] => http://twitter.com/search?q=%22Merry+Christmas%22
[promoted_content] =>
[query] => %22Merry+Christmas%22
[events] =>
)
[8] => stdClass Object
(
[name] => SarıLaci Sevdalıları Seri Takipleşiyor
[url] => http://twitter.com/search?q=%22Sar%C4%B1Laci+Sevdal%C4%B1lar%C4%B1+Seri+Takiple%C5%9Fiyor%22
[promoted_content] =>
[query] => %22Sar%C4%B1Laci+Sevdal%C4%B1lar%C4%B1+Seri+Takiple%C5%9Fiyor%22
[events] =>
)
[9] => stdClass Object
(
[name] => Михаил Калашников
[url] => http://twitter.com/search?q=%22%D0%9C%D0%B8%D1%85%D0%B0%D0%B8%D0%BB+%D0%9A%D0%B0%D0%BB%D0%B0%D1%88%D0%BD%D0%B8%D0%BA%D0%BE%D0%B2%22
[promoted_content] =>
[query] => %22%D0%9C%D0%B8%D1%85%D0%B0%D0%B8%D0%BB+%D0%9A%D0%B0%D0%BB%D0%B0%D1%88%D0%BD%D0%B8%D0%BA%D0%BE%D0%B2%22
[events] =>
)
)
[as_of] => 2013-12-23T22:48:53Z
[created_at] => 2013-12-23T22:33:04Z
[locations] => Array
(
[0] => stdClass Object
(
[name] => Worldwide
[woeid] => 1
)
)
)
)
答案 0 :(得分:0)
假设您输出的对象存储在$data
:
foreach ($data[0]->trends as $trend)
{
// Do something with $trend->name
}