I have the following array:
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
)
)
And I would like to first sort it according another array by type:
For example: $sort = array('football','basket');
And afterwards by year.
How can I do that?
Thanks.
Desired output should be:
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
)
)
I do not mind if we reset the index values.
Thanks.
Use
array_multisort. Assuming your array is$arr:To use an addictional array specifying type order, you could do:
Example link:
http://codepad.org/qhZCpbZE