$data = [
[
"id"=> 3957,
"group"=> 1,
"attend_number"=> "0001",
"username"=> "李设计",
"paiming"=> "6",
"memo"=> ""
],
[
"id"=> 3958,
"group"=> 1,
"attend_number"=> "0004",
"username"=> "李管家",
"paiming"=> "-3.33",
"memo"=> ""
],
[
"id"=> 3961,
"group"=> 1,
"attend_number"=> "0005",
"username"=> "李木工",
"paiming"=> "4",
"memo"=> ""
],
[
"id"=> 3964,
"group"=> 1,
"attend_number"=> "0008",
"username"=> "杨一",
"paiming"=> "4",
"memo"=> ""
],
[
"id"=> 3965,
"group"=> 1,
"attend_number"=> "0009",
"username"=> "杨二",
"paiming"=> "0",
"memo"=> ""
],
];
echo "--------------原数据-----------------";
echo "<pre>";print_r($data);
// 你可以使用 array_column() 代替上面的代码
$volume = array_column($data, 'paiming');
echo "<pre>";print_r($volume);
// $values = array_values(array_flip(array_flip($volume)));
$values = array_flip(array_flip($volume));
echo "<pre>";print_r($values);
rsort($values);
echo "<pre>";print_r($values);die();
// echo "<pre>";print_r($values);
$key_values = []; //获取所有不重复的排名成绩数据
foreach ($values as $key => $value) {
$key_values[$key+1] = $value;
}
// echo "<pre>";print_r($key_values);
//成绩与实际排名对应
$paiming_values = array_flip($key_values);
// echo "<pre>";print_r($paiming_values);
$edition = array_column($data, 'id');
// 将数据根据 volume 降序排列,根据 edition 升序排列
// 把 $data 作为最后一个参数,以通用键排序
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
echo "--------------排序后数据-----------------";
foreach ($data as $key => $value) {
$data[$key]['other_paiming'] = isset($paiming_values[$value['paiming']]) ? $paiming_values[$value['paiming']] : 0 ;
}
echo "<pre>";print_r($data);die();