我有這個數組,它已經按'name'ASC排序。使用其中一個值對多維數組進行排序,同時遵守其順序php
array
0 =>
array
'id' => '4'
'name' => 'iPad'
'games' => 5
1 =>
array
'id' => '5'
'name' => 'iPhone'
'games' => 5
2 =>
array
'id' => '6'
'name' => 'Nintendo DS'
'games' => 5
3 =>
array
'id' => '1'
'name' => 'Playstation 2'
'games' => 2
4 =>
array
'id' => '7'
'name' => 'Playstation 3'
'games' => 2
5 =>
array
'id' => '7'
'name' => 'Xbox 360'
'games' => 1
如果'遊戲'的值相同,我想按'遊戲'的值排序,同時尊重排序'名稱'的順序。
結果應該是這樣的:
array
0 =>
array
'id' => '7'
'name' => 'Xbox 360'
'games' => 1
1 =>
array
'id' => '1'
'name' => 'Playstation 2'
'games' => 2
2 =>
array
'id' => '7'
'name' => 'Playstation 3'
'games' => 2
3 =>
array
'id' => '4'
'name' => 'iPad'
'games' => 5
4 =>
array
'id' => '5'
'name' => 'iPhone'
'games' => 5
5 =>
array
'id' => '6'
'name' => 'iPod Touch'
'games' => 5
我幾乎嘗試了所有種類的功能和用戶自定義的比較函數,但找不到合適的人。
如果可能的話,如果我想要'遊戲'DESC,並且如果遊戲的價值是相同的,那麼在維護排序後的'名稱'ASC時該如何處理呢?例如:
array
0 =>
array
'id' => '6'
'name' => 'Nintendo DS'
'games' => 5
1 =>
array
'id' => '5'
'name' => 'iPhone'
'games' => 5
2 =>
array
'id' => '4'
'name' => 'iPad'
'games' => 5
3 =>
array
'id' => '1'
'name' => 'Playstation 2'
'games' => 2
4 =>
array
'id' => '7'
'name' => 'Playstation 3'
'games' => 2
5 =>
array
'id' => '7'
'name' => 'Xbox 360'
'games' => 1
你使用mysql來拉數據嗎?你可以使用2順序而不是從php – 2012-04-18 01:37:30