-4

我从运行 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
                )
            )

提前致谢!

4

5 回答 5

3

像任何其他数组一样索引它。查看其实际来源print_r可能比将其全部串在一行中更有帮助。

$arr['data'][0]['data']['article']['url']
于 2012-04-28T16:59:51.173 回答
1
$url=$myArray['data'][0]['data']['article']['url']; //assuming $myArray is array
于 2012-04-28T17:02:22.400 回答
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
        ) 
      )
    )
  )
)
于 2012-04-28T17:01:36.303 回答
0

用这个

$array['data'][0]['data']['article']['url']

如果您的数组变量称为 $array.

于 2012-04-28T16:59:21.250 回答
0

如果要使用其键访问数组:

$array["key_name"] , $array[$key_name]

如果要使用元素顺序访问数组:

$array[0], $array[1] 

如果选择的结果是数组,可以继续使用 [] 深入:

假设 $array["key"] 包含一个数组,并且该数组具有“another_key”键值;

$array["key"]["another_key"] 

也会起作用。

于 2012-04-28T17:01:34.620 回答