$values = array_values($array);//建立一個數字索引的數組
$ch=$choice==0?max:min;//參數$choice爲0按從小到大排列,否則其他都默認爲按從大到小
do {
$val = $ch($values);//找出最大或最小值
$key = array_search($val,$values);//取得最大值的鍵名
$result[$key] = $val;//將最大值存入新數組
unset($values[$key]);
}while (count($values)>0);
return $result;
}