几种排名算法

自上次写完随笔以来,2个多月没写啦,这次总结下几种工作中常用的排名。其实比较简单,我们争取用最少的代码实现功能。

准备数组:

$info = [
["id" => "a", "vote_num" => 7],
["id" => "b", "vote_num" => 3],
["id" => "c", "vote_num" => 3],
["id" => "d", "vote_num" => 7],
["id" => "e", "vote_num" => 2],
["id" => "f", "vote_num" => 5],
];

第一种:

常规排序:(根据数组的键值拿到排序)

array_multisort(array_column($info,'vote_num'),SORT_DESC,$info);
foreach ($info as $k=>&$item){
$item['rank'] = $k+1;
}
echo '<pre>';
print_r($info);

几种排名算法

 

 



 

上一篇:Waves区块链—Waves Enterprise区块链电子投票系统如何助力大选公开透明化?


下一篇:(JavaIO编程案例)投票选举