簡體   English   中英

如何訪問此多維數組的鍵?

[英]How to access a key of this multidimensional array?

我已經將我的facebook post的JSON輸出轉換為數組,並且要在post中搜索特定的關鍵字,我必須訪問[message]鍵,因此如何訪問以下[0]和[1]鍵的[message]

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
        )

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

應該做的工作

假設$ foo是您的完整數組...

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

或循環:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM