I have an array that looks like this (sample):
Array
(
[1600] => Array
(
[country] => Canada
[memTypeID] => 10
)
[1601] => Array
(
[country] => United States
[memTypeID] => 7
)
[1602] => Array
(
[country] => Canada
[memTypeID] => 9
)
)
I need to sort by country and then memTypeID, while preserving the array key (in PHP). I believe I need to use uksort, as usort rewrites the array keys. I know how to create a simple comparison function on one array element, but am at a loss as to how I can handle two.
The resulting array should be:
Array
(
[1602] => Array
(
[country] => Canada
[memTypeID] => 9
)
[1600] => Array
(
[country] => Canada
[memTypeID] => 10
)
[1601] => Array
(
[country] => United States
[memTypeID] => 7
)
)
1 Answer