I have the following array. I'm trying to sort it by a bunch of custom values.
Array
(
[0] => Array
(
[item] => 'apple'
[quality] => 3
[store] => 'freds'
[price] => 2
)
[1] => Array
(
[item] => 'pear'
[quality] => 1
[store] => 'bobs'
[price] => 3
)
[2] => Array
(
[item] => 'banana'
[quality] => 2
[store] => 'freds'
[price] => 1
)
[3] => Array
(
[item] => 'kiwi'
[quality] => 2
[store] => 'sams'
[price] => 4
)
[4] => Array
(
[item] => 'coconut'
[quality] => 2
[store] => 'sams'
[price] => 6
)
[5] => Array
(
[item] => 'lime'
[quality] => 3
[store] => 'sams'
[price] => 5
)
)
First sort it by quality, lowest number first. If the quality is the same then sort it by store from this custom array in the order it's in. So it would put bob's first and sam's second etc..
Array(0=>'bobs',1=>'sams',2=>'freds')
and then if it's the same store then it sort's by price from highest to lowest.
So the array should be
[1] => Array
(
[item] => 'pear'
[quality] => 1
[store] => 'bobs'
[price] => 3
)
[2] => Array
(
[item] => 'coconut'
[quality] => 2
[store] => 'sams'
[price] => 6
)
[3] => Array
(
[item] => 'kiwi'
[quality] => 2
[store] => 'sams'
[price] => 4
)
[4] => Array
(
[item] => 'banana'
[quality] => 2
[store] => 'freds'
[price] => 1
)
[5] => Array
(
[item] => 'lime'
[quality] => 3
[store] => 'sams'
[price] => 5
)
[6] => Array
(
[item] => 'apple'
[quality] => 3
[store] => 'freds'
[price] => 2
)
I've tried a bunch of different combinations and can't figure it out. Is this possible just using usort, or do I need to just manually loop through the array and figure it out from there?