我想根据最终得分对这个数组数组进行排序,并保留我的键。我可以使用usort吗?怎么样 ?
Array
(
[2253472] => Array
(
[noOfDays] => 1
[bestAns] => 1
[finalScore] => 13.5
)
[2253465] => Array
(
[noOfDays] => 1
[bestAns] => 0
[finalScore] => 50
)
[2253473] => Array
(
[noOfDays] => 1
[bestAns] => 0
[finalScore] => 23
)
[2253471] => Array
(
[noOfDays] => 1
[bestAns] => 0
[finalScore] => 89
)
[2253464] => Array
(
[noOfDays] => 1
[bestAns] => 1
[finalScore] => 0.5
)
[2253415] => Array
(
[noOfDays] => 6
[bestAns] => 0
[finalScore] => 0.333
)
)
参考方案
所有你需要的是
// Ascending
usort($data, function ($a, $b) {
return $a['finalScore'] - $b['finalScore'];
});
要么
// Descending
usort($data, function ($a, $b) {
return $b['finalScore'] - $a['finalScore'];
});
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
PHP:对数组排序 - php请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…
PHP-将日期插入日期时间字段 - php我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数
PHP PDO组按列名称查询结果 - php以下PDO查询返回以下结果:$db = new PDO('....'); $sth = $db->prepare('SELECT ...'); 结果如下: name curso ABC stack CDE stack FGH stack IJK stack LMN overflow OPQ overflow RS…
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…