简体   繁体   English

如何使用PHP在数组中获取确切的键值?

[英]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 . 但我想如何获得精确关键字和值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.. json_decode()中存在问题,您必须像这样传递2个参数“ true”。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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