PHP multidimensional array sorting is a bit confusing to me.
What I have is an array I formed with json_decode() from a .jsonp file.
It has several variables in each primary array entry. They include "Year", "Month", "Day", "hourTimeStart", and "minuteTimeStart", along with some other information.
I'd like to sort this array by date, so I'd like to first sort by "minuteTimeStart", "hourTimeStart", "Day", then "Month", then "Year", so they're in chronological order.
The array looks like this:
Array (
[0] => Array ( [Year] => 2013 [Month] => February [Day] => 5 [hourTimeStart] => 5 [minuteTimeStart] => 0 [Name] => tht )
[1] => Array ( [Year] => 2013 [Month] => January [Day] => 6 [hourTimeStart] => 2 [minuteTimeStart] => 0 [Name] => gregre)
[2] => Array ( [Year] => 2013 [Month] => March [Day] => 4 [hourTimeStart] => 1 [minuteTimeStart] => 15 [Name] => gregre)
)
Essentially what I'm doing is this:
$databaseFileURL = "../Appointments/AllAppointmentData.jsonp";
if(file_exists($databaseFileURL)){
$jsonAppointmentData = file_get_contents($databaseFileURL);
} else $jsonAppointmentData = "";
$AppointmentData = json_decode($jsonAppointmentData, true);
Then I want to sort $AppointmentData by the date indicated in each sub-array
?. It's just a list of requirements. You'll probably want to read php.net/usort, which is what you'll probably end up using to accomplish your requirements.array_multisort()which only takes a few sorting criteria (ascending, descending, natural etc) and not a custom sorting function, as required here (the fields Year, Month, Day, Hour, Minute need to be combined into a value to make it comparable)