从JSON对象获取最大值

时间:2013-04-27 03:54:53

标签: php json

我从cURL中检索到$string,如下所示:

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

我想知道如何获得具有最大值的id(即974),我该如何在PHP中执行此操作?

1 个答案:

答案 0 :(得分:5)

$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"