dongshan7060
2015-11-07 06:10
浏览 20
已采纳

如何使用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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanpasi6287 2015-11-07 06:13
    已采纳
    foreach($response as $key => $val){
      echo "Key: " . $key . "Value: " . $val->detail;
    }
    
    打赏 评论
  • douji2520 2015-11-07 06:17

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

    $response = json_decode($result,true);
    print_r($response); 
    
    打赏 评论

相关推荐 更多相似问题