dsa45132 2013-04-27 03:54
浏览 902
已采纳

从JSON对象获取最大值

I have a $string retrieved from cURL like this:

{"time":0.01,"total_rows":7,"rows":[{"id":968},{"id":969},{"id":970},{"id":971},{"id":972},{"id":973},{"id":974}]}

I would like to know how to get the id that has the largest value (i.e 974), how can I do this in PHP?

  • 写回答

1条回答 默认 最新

  • duandao6414 2013-04-27 04:03
    关注
    $result = '{"time":0.01,"total_rows":7,"rows":[{"id":968},{"id":969},{"id":970},{"id":971},{"id":972},{"id":973},{"id":974}]}';
    $json = json_decode($result,true);
    $max = max($json["rows"]);
    echo $max["id"]; // "974"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?