這是我的數組。在同一陣列內移動具有相同值的數組
Array
(
[id] => 1
[color] => "White"
[something] => Array
(
[country] => "France"
[city] => "Paris"
)
)
Array
(
[id] => 2
[color] => "Black"
[something] => Array
(
[country] => "Germany"
[city] => "Berlin"
)
)
Array
(
[id] => 2
[color] => "Red"
[something] => Array
(
[country] => "Russia"
[city] => "Moscow"
)
)
我想將具有相同id
值的數組分組。這應該是輸出:
[0] => Array
(
[0] => Array
(
[id] => 1
[color] => "White"
[something] => Array
(
[country] => "France"
[city] => "Paris"
)
)
)
[1] => Array
(
[0] => Array
(
[id] => 2
[color] => "Black"
[something] => Array
(
[country] => "Germany"
[city] => "Berlin"
)
)
[1] => Array
(
[id] => 2
[color] => "Red"
[something] => Array
(
[country] => "Russia"
[city] => "Moscow"
)
)
)
我試圖用幾十foreach
聲明,但沒有辦法,我讓同一陣列內具有相同id
陣列。這可能與它是一個多維數組有關嗎?我應該用兩個嵌套的foreach
來得到結果嗎?
基本上我試着用數十個類似的功能沒有成功。感謝您的「結果」例子,我明白問題所在。我沒有在Array()中傳遞結果。我總是傳遞3個獨立的數組Array(1)Array(2)Array(3)而不是Array(Array(1)Array(2)Array(3))。謝謝CertaiN。 – user1274113 2013-05-15 08:47:41