In php how would I get the value 'error' in this array below? I did a var_dump($myArray);
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"
}
}
}
What I am actually looking for is to check the value of $myArray[0][0]; If my code works that value will be "id". If it didn't work it will be "error". So I need to see if it says "id" or "error".
2 Answers 2
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
}
1 Comment
In PHP you can access array elements by name. So to get the value of "error" type:
$value = $myArray[0]["error"];
$myArray[0]['error']['message'];var_dump( array_column($myArray, ''error" ));andvar_dump( array_column($myArray[0], ''error" ));