简体   繁体   中英

how to get exact key's value in array using PHP?

This is my code

$response = json_decode($result);
print_r($response);

and I got the result

  stdClass Object ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found 
[status] => 404 
[detail] => The requested resource could not be found. 
[instance] => ) 

and I added

foreach($response as $key=>$val)
{
    echo $key.'='.$val.'<br>';
}

But I want how to get exact key and value for detail . How to get it? Thanks

foreach($response as $key => $val){
  echo "Key: " . $key . "Value: " . $val->detail;
}

There is a problem in json_decode(), you have to pass 2 parameter "true", like this..

$response = json_decode($result,true);
print_r($response); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM