如何从这个嵌套数组中获取值

时间:2012-07-01 11:01:02

标签: php arrays multidimensional-array

var_dump($ib);给出了以下输出:

array (
  'data' => array (
    0 => array ( 
      'id' => '2015469353355_151',
      'from' => array ( 
         'name' => 'Aah',
         'id' => '100000292544713',
      ),
      'message' => 'zzzz',
      'created_time' => '2012-06-08T06:16:41+0000',
      ),
    1 => array (
      'id' => '2015469353355_152',
      'from' => array (
        'name' => 'assaaaa',
        'id' => '100000292544713',
      ),
      'message' => 'zzzz',
      'created_time' => '2012-06-08T06:16:51+0000',
    ),
  ),
  'paging' => array (
    'previous' => 'https://graph.facebook.com/2015469353355/comments?limit=25&value=1&redirect=1&__paging_token=2015469353355_175&access_token=AAAFfJS6rRAABAHKGZCy57ZCrSEdQL2kUIYqZAcNBLkbnKTBxRhhx9CTvnUlq2LcAK1kZBWnV6AH5RpvkmGYRFzvk12kNXLe6OhjjapH5PEIUwv1h2tYl&since=1340009948&__previous=1',
  'next' => 'https://graph.facebook.com/2015469353355/comments?limit=25&value=1&redirect=1&access_token=AAAFfJS6rRAABAHKGZCy57ZCrSEdQL2kUIYqZAcNBLkbnKTBxRhhx9CTvnUlq2LcAK1kZBWnV6AH5RpvkmGYRFzvk12kNXLe6OhjjapH5PEIUwv1h2tYl&until=1340009948&__paging_token=2015469353355_175',
  ),
)

如何检索'next'的值?

3 个答案:

答案 0 :(得分:5)

您可以通过执行以下操作获取next的值

echo $ib['paging']['next'];

答案 1 :(得分:4)

$array["paging"]['next']

如果我们假设主数组已分配给变量$array

答案 2 :(得分:3)

由于paging是主数组的索引,因此它本身也是 数组。您可以使用其索引向下钻取并获取所需的信息。

$ib['paging']会给你 -

paging => array (
  'previous' => '...',
  'next' => '...',
)

接下来的步骤是深入查看您再次返回next索引的数组。所以你最终得到的是一个指定索引中索引的语句。

$ib['paging']['next'];

如果next参数一个数组,你甚至可以进一步使用另一个索引 -

paging => array (
  'previous' => '...',
  'next' => array(
     'url'=>'https://graph.facebook...'
  ),
)

// this will give us `'https://graph.facebook...'`
echo $ib['paging']['next']['url'];