如何访问这个多维数组的键?

时间:2013-12-18 00:36:49

标签: php multidimensional-array

我已将facebook帖子的JSON输出转换为数组,并且为了在帖子中搜索特定关键字,我必须访问[message]键,以便如何访问[0]的[strong> [message] ],[1]下面的键:

Array
(
    [0] => Array
        (
            [id] => 459037547545408_496947267087769
            [from] => Array
                (
                    [category] => Internet/software
                    [name] => Open Pdf Library
                    [id] => 459037547545408
                )

            [message] => No
            [privacy] => Array
                (
                    [value] => 
                )

            [type] => status
            [status_type] => mobile_status_update
            [created_time] => 2013-12-17T22:55:55+0000
            [updated_time] => 2013-12-17T22:55:55+0000
        )

    [1] => Array
        (
            [id] => 459037547545408_496947230421106
            [from] => Array
                (
                    [category] => Internet/software
                    [name] => Open Pdf Library
                    [id] => 459037547545408
                )

            [message] => Hello star
            [privacy] => Array
                (
                    [value] => 
                )

            [type] => status
            [status_type] => mobile_status_update
            [created_time] => 2013-12-17T22:55:46+0000
            [updated_time] => 2013-12-17T22:55:46+0000
        )

    )

2 个答案:

答案 0 :(得分:0)

<?php
  echo $array[0]["message"];
  echo "<br>";
  echo $array[1]["message"];
?>

应该做的工作

答案 1 :(得分:0)

假设$ foo是你的完整阵列......

$foo[0]['message'];
$foo[1]['message'];

或循环:

foreach ($foo as $bar) {
   echo $bar['message'];
}