我有一個多維數組數組,代表連接到我們的服務器的用戶列表。每個數組都包含有關連接的信息。同一個用戶可以連接到不同服務器上的任意數量的端口。以組的形式輸出多維數組
Array( [0] => Array(
[0] => serverA
[1] => port1,
[2] => user1,
[3] => ip1
),
[1] => Array(
[0] => serverB
[1] => port2,
[2] => user2,
[3] => ip2
),
[2] => Array(
[0] => serverC
[1] => port1,
[2] => user3,
[3] => ip3
),
[3] => Array(
[0] => serverA
[1] => port1,
[2] => user4,
[3] => ip4
),
[4] => Array(
[0] => serverB
[1] => port4,
[2] => user5,
[3] => ip5
),
[5] => Array(
[0] => serverC
[1] => port1,
[2] => user6,
[3] => ip6
),
[6] => Array(
[0] => serverA
[1] => port2,
[2] => user7,
[3] => ip7
),
)
我需要通過小組第一的服務器,然後端口和打印出來的清單顯示每個服務器和端口所連接的用戶,如下:
ServerA
port1
user1,ip1
user4,ip4
port2
user7,ip2
ServerB
port2
user2,ip2
port4
user5,ip5
ServerC
port1
user3,ip3
user6,ip6
我很困惑,如何來解決這個問題。我應該使用多維數組排序函數(例如array_multisort)還是應該構建一個新的數組?一個例子將不勝感激。
對不起,愚蠢的錯誤。我編輯了數組。 – Michelle 2011-06-09 09:21:21