我有以下的數組:多次排序以陣列
Array
(
[0] => Array
(
[note] => test
[year] => 2011
[type] => football
)
[1] => Array
(
[note] => test1
[year] => 2010
[type] => basket
)
[2] => Array
(
[note] => test2
[year] => 2012
[type] => football
)
[3] => Array
(
[note] => test3
[year] => 2009
[type] => basket
)
[4] => Array
(
[note] => test4
[year] => 2010
[type] => football
)
)
我想先根據另一個陣列按類型進行排序它:
例如:$sort = array('football','basket');
而且事後年。
我該怎麼做?
謝謝。
所需的輸出應該是:
Array
(
[2] => Array
(
[note] => test2
[year] => 2012
[type] => football
)
[0] => Array
(
[note] => test
[year] => 2011
[type] => football
)
[4] => Array
(
[note] => test4
[year] => 2010
[type] => football
)
[1] => Array
(
[note] => test1
[year] => 2010
[type] => basket
)
[3] => Array
(
[note] => test3
[year] => 2009
[type] => basket
)
)
我不介意我們重置索引值。
謝謝。
感謝隊友似乎工作。但是我怎樣才能包含$ sortBy數組呢? – glarkou 2012-07-29 09:16:12
@salamis我編輯了我的答案,以覆蓋這一點。 – lafor 2012-07-29 09:40:58
感謝隊友,它似乎按預期工作。一個快速的問題。爲什麼我們仍然使用'$ type,SORT_ASC'如果我們正在用另一個數組排序呢? – glarkou 2012-07-29 09:49:00