I have the following bidimensional indexed array of multiple one-dimensional associative arrays:
Array (
[0] => Array (
[from] => Person 1
[to] => Person 2
[platform] => Instagram Direct Messaging
[date] => 2016/06/27
[time] => 12:00
[ampm] => PM
[specialcontent] => none
[content] => Hello
)
[1] => Array (
[from] => Person 1
[to] => Person 2
[platform] => Instagram Direct Messaging
[date] => 2016/06/27
[time] => 12:00
[ampm] => PM
[specialcontent] => none
[content] => How are you?
)
[2] => Array (
[from] => Person 2
[to] => Person 1
[platform] => Instagram Direct Messaging
[date] => 2016/06/27
[time] => 6:00
[ampm] => PM
[specialcontent] => none
[content] => Oh, hey there. I'm fine
)
[3] => Array (
[from] => Person 2
[to] => Person 1
[platform] => Instagram Direct Messaging
[date] => 2016/06/27
[time] => 6:01
[ampm] => PM
[specialcontent] => none
[content] => What about you?
)
)
I'd like to sort the inner arrays by the value of the date
field (key) in them, which means, I have to order them by year, then by month, and then by day, in an ascending order. I can get such values from the date
(key) using the following commands, respectively: $year = substr($item['date'], 0, 4);
, $month = substr($item['date'], 5, 2);
, $day = substr($item['date'], -2);
. I also know I perhaps need to use a function like usort
or array_multisort
, but I can't think of how to create a function that returns the order of the arrays by the year, then month, then day of their date
keys.