0

私はこれが以前に投稿されたことを知っていますが、私のためにそれを働かせることができませんでした:s理由がわかりません! しかし、anywhooo 私の配列 $servers は次のようになります

Array
(
    [0] => Array
        (
            [0] => Dell PowerEdge R210 II
            [1] => 8
            [2] => Array
                (
                    [0] => 8
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

    [1] => Array
        (
            [0] => Dell PowerEdge R210 II 2
            [1] => 2
            [2] => Array
                (
                    [0] => 2
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

    [2] => Array
        (
            [0] => Dell PowerEdge R210 II 3
            [1] => 3
            [2] => Array
                (
                    [0] => 3
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

    [3] => Array
        (
            [0] => Dell PowerEdge R210 II 4
            [1] => 4
            [2] => Array
                (
                    [0] => 4
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

    [4] => Array
        (
            [0] => Dell PowerEdge R210 II 5
            [1] => 5
            [2] => Array
                (
                    [0] => 5
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

    [5] => Array
        (
            [0] => Dell PowerEdge R210 II 6
            [1] => 6
            [2] => Array
                (
                    [0] => 6
                    [1] => Sock
                    [2] => Price
                    [3] => ImageURL
                    [4] => CPU
                    [5] => Memory
                    [6] => HDD
                    [7] => Bandwidth
                    [8] => OS
                    [9] => Upgrades
                    [10] => OrderLink
                )

        )

)

配列を再配置して $servers に戻したいのですが、$servers[x][1] の順序で

では、特異数がどこにあるのか (1 番目のオブジェクトは 8)、最小の番号から最大の番号に移動して並べ替えたいと思います。

どうもありがとう

ps私はこれを試しました

<?php
function cmp($a, $b)
{
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}

$a = array(3, 2, 5, 6, 1);

usort($servers, "cmp");
?>

しかし、それはうまくいかないようでした!

ありがとう

4

1 に答える 1

1

あなたcmpは間違っています。$a$bのような配列です

Array
    (
        [0] => Dell PowerEdge R210 II 6
        [1] => 6
        [2] => Array
            (
                [0] => 6
                [1] => Sock
                [2] => Price
                [3] => ImageURL
                [4] => CPU
                [5] => Memory
                [6] => HDD
                [7] => Bandwidth
                [8] => OS
                [9] => Upgrades
                [10] => OrderLink
            )

    )

$a[1]と比較する必要があります$b[1]:

function cmp($a, $b) {
    return $a[1] - $b[1];
}
于 2012-07-18T17:02:45.890 に答える