['a'=>200,'b'=>100,'c'=>100],写一个自定义排序函数,按值降序,如果值一样,按键排序
function kvsort($arr) {
$res_arr = [];
while (count($arr)) {
$min = null;
$min_key = null;
foreach ($arr as $key=>$value) {
if(!$min || $min > $value) {
$min = $value;
$min_key = $key;
} else if($min == $value && $min_key > $key) {
$min = $value;
$min_key = $key;
}
}
unset($arr[$min_key]);
$res_arr[$min_key] = $min;
}
return $res_arr;
}