2

我想对数组进行数字排序,即 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);但它对连字符键的效果不太好,除非我做错了什么?

4

1 回答 1

8

您可以使用uksort()withstrnatcmp()作为比较功能:

uksort($array, 'strnatcmp');
于 2012-12-31T00:51:00.190 回答