Given a multidimensional array like this:
$data = array (
[0] => array('aDate' => '2016-01-10', 'tType' => 'Added'),
[1] => array('aDate' => '2016-01-30', 'tType' => 'RtrnCap'),
[2] => array('aDate' => '2016-01-20', 'tType' => 'Removed'),
[3] => array('aDate' => '2016-01-20', 'tType' => 'RtrnCap')
);
How do I sort this array to get this:
$data = array (
[0] => array('aDate' => '2016-01-10', 'tType' => 'Added'),
[1] => array('aDate' => '2016-01-20', 'tType' => 'RtrnCap'),
[2] => array('aDate' => '2016-01-20', 'tType' => 'Removed'),
[3] => array('aDate' => '2016-01-30', 'tType' => 'RtrnCap')
);
Where the sort is first on aDate
in ascending order and the second sort is tType
custom sorted in the following order: Added, RtrnCap, Removed.
I have searched solutions using multisort like this SO question for "multiple keys" and usort (using an anonymous function) like this SO question to custom sort one key. Each of these is only half of the solution. The TWO sort example uses normal Ascending or Descending sort orders (I need one to be custom order). The custom usort example works fine but its only one set of values.
Bottom line: I need two sorts: the first sort is date ascending, the second one custom.