这是我从twitter API调用返回的数组的第一部分。我正在尝试提取[expanded_url]变量并将其存储到另一个数组中。我已经为[id]或[text]等顶级项目工作了,但我不确定如何访问更深层次的元素。
Array
(
[statuses] => Array
(
[0] => Array
(
[metadata] => Array
(
[iso_language_code] => en
[result_type] => recent
)
[created_at] => Thu Mar 26 21:02:42 +0000 2015
[id] => 581199619855650816
[id_str] => 581199619855650816
[text] => RT @JamilSays: 150 people recently died in a plane crash, ISIS is beheading innocent people, and you guys are bitching over Zayn leaving 1D…
[source] => Twitter for iPhone
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[user] => Array
(
[id] => 546187115
[id_str] => 546187115
[name] => Medina ✨
[screen_name] => Medinabtnc
[location] =>
[profile_location] =>
[description] => Bosnia and Herzegovina // Belgium // FC BAYERN MÜNCHEN ♡
[url] => http://t.co/z1LwFoDZ6U
[entities] => Array
(
[url] => Array
(
[urls] => Array
(
[0] => Array
(
[url] => http://t.co/z1LwFoDZ6U
[expanded_url] => http://izzzyyxo.tumblr.com
[display_url] => izzzyyxo.tumblr.com
[indices] => Array
(
[0] => 0
[1] => 22
)
)
)
)
[description] => Array
(
[urls] => Array
(
)
)
)
这是我用来访问和回显[id]的代码。我需要修改它以找到[expanded_url]
foreach($string['statuses'] as $items)
{
echo $items['id']."<br />";
}
一旦我能够在循环中对[expanded_url]进行微调,如果可能的话,我想将每个url存储到一个数组中!
这似乎在大多数情况下都有效,尽管有时确实会导致错误。
foreach($string['statuses'] as $items)
{
if($items['user']['entities']['url']['urls']['0']['expanded_url'] !="")
echo $items['user']['entities']['url']['urls']['0']['expanded_url']."<br />";