PHP在多维数组中获取值 [英] PHP getting values in multidimensional array
本文介绍了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
}
这篇关于PHP在多维数组中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文