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

时间:2015-11-07 06:10:51

标签: php

这是我的代码

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

我得到了结果

  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] => ) 

我加了

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

但我想知道如何获得detail的确切密钥和值。怎么弄? 感谢

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

json_decode()中存在问题,您必须传递2参数&#34; true&#34;,就像这样..

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