Given this array:
Array ( [0] => Array ( [status] => closed [userModifiedAt] => 2015-12-09T11:47:46Z ) [1] => Array ( [status] => active [userModifiedAt] => 2016-02-08T16:43:26Z ) [2] => Array ( [status] => closed [userModifiedAt] => 2016-03-31T03:47:19Z ) [3] => Array ( [status] => pending [userModifiedAt] => 2015-12-08T14:09:58Z )
I would like to order it by [status] using this order: - pending - active - closed
And for each state, the order is [userModifiedAt].
I am using this code:
usort($array, function($a,$b){ return strcmp($a['status'], $b['status']);} );
But it works in alphabetical order, so the status is ordered as: - active - closed - pending
How can I arrange the array according to a predefined list of orders?
source share