我从运行php代码得到以下输出,现在我想从以下数组中获取“url”字段,我该怎么做到?
Array (
[data] => Array (
[0] => Array (
[id] => xxxxx
[from] => Array (
[id] => xxxxxx
[name] => abc
)
[start_time] => 2012-04-28T07:49:17+0000
[end_time] => 2012-04-28T07:49:17+0000
[publish_time] => 2012-04-28T07:49:17+0000
[application] => Array (
[id] => 389407107765872
[name] => Ki News Social Reader
)
[data] => Array (
[article] => Array (
[id] => 10150703062718596
[url] => http://example.com
[type] => kinewssocialreader:article
[title] => story
)
)
提前致谢!
答案 0 :(得分:3)
像任何其他数组一样索引它。查看print_r
的实际来源比看到它们在一行中串联起来更有帮助。
$arr['data'][0]['data']['article']['url']
答案 1 :(得分:1)
$url=$myArray['data'][0]['data']['article']['url']; //assuming $myArray is array
答案 2 :(得分:0)
使用此
$array['data'][0]['data']['article']['url']
如果您的数组变量名为$ array。
答案 3 :(得分:0)
如果要使用密钥访问阵列:
$array["key_name"] , $array[$key_name]
如果要使用元素顺序访问数组:
$array[0], $array[1]
如果选择的结果是数组,则可以继续使用[]更深入:
假设$ array [“key”]包含一个数组,并且该数组具有“another_key”键值;
$array["key"]["another_key"]
也会奏效。
答案 4 :(得分:0)
假设我正确地读取数据结构,那就是:
$variableName['data'][0]['data']['article']['url']
其中 $ variableName 是顶级数组的名称。括号不平衡,所以我不能100%确定结构。
我把结构看成是这样的。如果这与您的结构匹配,则上面的命名将起作用。
Array (
[data] => Array (
[0] => Array (
[id] => xxxxx
[from] => Array (
[id] => xxxxxx
[name] => abc
)
[start_time] => 2012-04-28T07:49:17+0000
[end_time] => 2012-04-28T07:49:17+0000
[publish_time] => 2012-04-28T07:49:17+0000
[application] => Array (
[id] => 389407107765872
[name] => Ki News Social Reader
)
[data] => Array (
[article] => Array (
[id] => 10150703062718596
[url] => http://example.com
[type] => kinewssocialreader:article [title] => story
)
)
)
)
)