对具有最高点的数组进行排序?
如何对 15.00
键中具有最高点的数组进行排序?
我有一个如下所示的数组:
Array
(
[9] => Array
(
[15.00] => 3.0
[20.00] => 8.0
[25.00] => 10.5
)
[2] => Array
(
[15.00] => 2.0
[20.00] => 5.0
[25.00] => 2.5
)
[4] => Array
(
[15.00] => 6.0
[25.00] => 4.0
[30.00] => 6.0
)
)
按顺序应该是: 4、9 和 2
How do I sort array that has highest point from 15.00
key?
I have an array look like this:
Array
(
[9] => Array
(
[15.00] => 3.0
[20.00] => 8.0
[25.00] => 10.5
)
[2] => Array
(
[15.00] => 2.0
[20.00] => 5.0
[25.00] => 2.5
)
[4] => Array
(
[15.00] => 6.0
[25.00] => 4.0
[30.00] => 6.0
)
)
In order it should be: 4, 9 and 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PHP 有
usort
,一个可以让你排序的函数通过用户提供的比较函数。还有uasort
维护索引关联。这是一个示例:
它正在工作。
希望这有帮助。
PHP has
usort
, a function enabling you to sort via a user-provided comparison function. There's alsouasort
that maintains index association.Here's an example:
And here's it working.
Hope this helps.
如果我正确理解你的问题,我个人可能会使用 usort() 。在我的回调中,我会比较
$a[15.00]
和$b[15.00]
。If I understand your question correctly, I would personally probably use usort(). In my callback I would compare
$a[15.00]
and$b[15.00]
.你想要 uasort():
You want uasort():