我的代碼如下usort()排列
$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
效應初探,而不是所有的人都在一起,他們是否有辦法解決這個問題?
從循環中刪除它。 – str 2013-03-25 15:11:07
在排序之前將三個數據數組合併成一個數組。 – CBroe 2013-03-25 15:11:31
無關:'json_decode(「json api response url」),true);'那裏有太多的右括號(還有其他兩行) – scones 2013-03-25 15:12:45