如何根据$rr
中的升序排序整个$rr[xx]->label
?
$result=curl_exec ($ch);
$rr = json_decode($result);
foreach($rr as $k=>$v) {
echo $v->label . ' - ' . $v->id . '<Br/>';
}
输出:
Oman - 500
Uk - 99
America - 100
Denmark - 120
预期输出(按标签排序):
America - 100
Denmark - 120
Oman - 500
Uk - 99
答案 0 :(得分:2)
<?php
$arr= array("Oman"=>"500","uk"=>"99","America "=>"100","Denmark "=>"120");
ksort($arr);
foreach($arr as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
使用ksort - sorts an associative array in ascending order, according to the value