-1

嗨,我实际上是在尝试使用不同的键对第三级的数组进行排序。

下面是样本数组输入。

Array
(
    [19067] => Array
        (
            [Morrisville, PA] => 5.02
        )

    [18977] => Array
        (
            [Washington Crossing, PA] => 6.63
        )

    [08695] => Array
        (
            [Trenton, NJ] => 2.84
        )

    [08690] => Array
        (
            [Trenton, NJ] => 1
        )

    [08666] => Array
        (
            [Trenton, NJ] => 2.84
        )

    [08650] => Array
        (
            [Trenton, NJ] => 0
        )

    [08648] => Array
        (
            [Lawrence Township, NJ] => 2.88
        )

    [08647] => Array
        (
            [Trenton, NJ] => 2.84
        )

    [08646] => Array
        (
            [Trenton, NJ] => 2
        )

)

任何人都可以帮我在第三级对上述数组进行排序吗

预期的结果应该是:

输出:

Array
(
    [08650] => Array
        (
            [Trenton, NJ] => 0
        )

    [08690] => Array
        (
            [Trenton, NJ] => 1
        )   

     [08646] => Array
        (
            [Trenton, NJ] => 2
        )

    [08666] => Array
        (
            [Trenton, NJ] => 2.84
        )   

    [08695] => Array
        (
            [Trenton, NJ] => 2.84
        )

    [08647] => Array
        (
            [Trenton, NJ] => 2.84
        )

    [08648] => Array
        (
            [Lawrence Township, NJ] => 2.88
        )

    [19067] => Array
        (
            [Morrisville, PA] => 5.02
        )

    [18977] => Array
        (
            [Washington Crossing, PA] => 6.63
        )   


)

提前致谢..

4

1 回答 1

2
uasort($array, function (array $a, array $b) {
    return current($a) - current($b);
});

请注意注释:差异小于 1.0 的值将被排序为相同。您可能想要执行(current($a) - current($b)) * 100或以其他方式舍入该值,具体取决于您期望的值范围。

于 2012-09-03T15:22:56.613 回答