对多维数组中的值进行排名
我有一个已经排序的数组,但我想对每一行进行排名。如果存在匹配值,那么它将跳过像 1,2,2,4,5,5,5,8 这样的排名。
它可能会在任何列上排序,但在下面的示例中,它会在 a 和 b 上排序。当数组 0 和 1 匹配时,下面的排名将为 1,1,3。
数组示例
Array
(
[0] => Array
(
[rank] =>
[a] => 5
[b] => 4
[c] => 1
)
[1] => Array
(
[rank] =>
[a] => 5
[b] => 4
[c] => 9
)
[2] => Array
(
[rank] =>
[a] => 3
[b] => 25
[c] => 9
)
)
I have an array that is already sorted but i want to give a ranking to each row. If there are matching values then it will skip a rank like 1,2,2,4,5,5,5,8.
It could potentailly be sorted on any columns but in the example below it is sorted on a and b. The rank below would be 1,1,3 as arrays 0 and 1 match.
Example array
Array
(
[0] => Array
(
[rank] =>
[a] => 5
[b] => 4
[c] => 1
)
[1] => Array
(
[rank] =>
[a] => 5
[b] => 4
[c] => 9
)
[2] => Array
(
[rank] =>
[a] => 3
[b] => 25
[c] => 9
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其中
$arr
是您的数组:Where
$arr
is your array: