我的代码如下
$results = array();
$results[] = json_decode("json api response url", true);
$results[] = json_decode("json api response url 2", true);
$results[] = json_decode("json api response url 3", true);
foreach($results as $result) {
$decoded = $result['Info'];
usort($decoded, function($a, $b) { return $a['price'] > $b['price'] ? 1 : -1; });
foreach($decoded as $row) {
echo $row['price'];
}
}
JSON数组返回如下
["Info"]=>
[0]=>
array(13) {
["price"]=>
int(3000)
}
[1]=>
array(13) {
["price"]=>
int(5000)
它usort
为每个json_decode
响应而不是所有响应都做一个,他们是否可以解决这个问题?