PHP在多维数组中获取值

问题描述:

在php中,我如何在下面的此数组中获得值错误"?我做了var_dump($myArray);

In php how would I get the value 'error' in this array below? I did a var_dump($myArray);

我尝试回显$myArray[0][0];$myArray[0];,但是它们都不起作用.

I tried echo $myArray[0][0]; and $myArray[0]; but neither of these worked.

array(1) {
      [0]=>
      array(1) {
        ["error"]=>
        array(4) {
          ["message"]=>
          string(27) "Invalid OAuth access token."
          ["type"]=>
          string(14) "OAuthException"
          ["code"]=>
          int(190)
          ["fbtrace_id"]=>
          string(11) "GJb4ZZLyAll"
        }
      }
    }

我实际上正在寻找的是检查$ myArray [0] [0]的值;如果我的代码有效,则该值为"id".如果它不起作用,那将是错误".所以我需要看看它是说"id"还是"error".

根据我的理解,您想检查密钥的值.因此,我们可以通过 array_keys() 将键作为数组来获得然后,您可以访问第一个密钥并检查它是id还是error,例如

As from my understanding you want to check the value of the key. So we get the keys as an array with array_keys(), with this you then can access the first key and check if it is id or error, e.g.

$keys = array_keys($myArray[0]);

if($keys[0] == "id") {
    //good
} elseif($keys[0] == "error") {
    //bad
}