gpt4 book ai didi

php - 按键对数组进行数字排序

转载 作者:行者123 更新时间:2023-12-02 07:04:55 25 4
gpt4 key购买 nike

我想对数组进行数字排序,即188、188-1、188-2、222、222-1、222,-2等。这是数组当前的外观:

[188-1] => Array
(
[time] => 1
)

[188-2] => Array
(
[time] => 2
)

[188-3] => Array
(
[time] => 3
)

[188] => Array
(
[notes] => frog stand notes
)

[489] => Array
(
[notes] => notes
)

[489-1] => Array
(
[weight] => 10
[reps] => 30
)

[489-2] => Array
(
[weight] => 20
[reps] => 30
)

[489-3] => Array
(
[weight] => 30
[reps] => 30
)

[492-1] => Array
(
[weight] => 500
[distance] => 100000
)

[492] => Array
(
[notes] => more notes
)

我尝试了一种ksort ksort($sorted, SORT_DESC);,但它不能与带连字符的键一起使用,除非我做错了什么?

最佳答案

您可以将 uksort() strnatcmp() 用作比较函数:

uksort($array, 'strnatcmp');

关于php - 按键对数组进行数字排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com