So I'm developing a message system for a project I'm working on and I want to organize an array of conversations by the latest message datetime.
Here's my array:
Array(
[0] = Array (
[ID] => 1,
[USER] => 1,
[AUTHOR] => 2,
[TITLE] => Welcome to the Site!,
[DATETIME] => 2016-09-12 20:41:16,
[MESSAGES] => Array (
[0] => Array (
[ID] => 1,
[CONVERSATION] => 1,
[USER] => 1,
[CONTENT] => Welcome to the site User!,
[DATETIME] => 2016-09-13 00:19:20
)
[1] => Array (
[ID] => 2,
[CONVERSATION] => 1,
[USER] => 2,
[CONTENT] => Thanks for welcoming me!,
[DATETIME] => 2016-09-13 00:27:54
)
)
[1] = Array (
[ID] => 2,
[USER] => 2,
[AUTHOR] => 1,
[TITLE] => Hello World!,
[DATETIME] => 2016-09-13 00:29:59,
[MESSAGES] => Array (
[0] => Array (
[ID] => 1,
[CONVERSATION] => 1,
[USER] => 1,
[CONTENT] => This is a test post.,
[DATETIME] => 2016-09-13 00:19:45
)
[1] => Array (
[ID] => 2,
[CONVERSATION] => 1,
[USER] => 2,
[CONTENT] => This is an example response.,
[DATETIME] => 2016-09-13 00:45:04
)
)
)
What I want to do is organise the array of conversations using the most recent message's datetime so the conversation with the most recent message will be first, the conversation with the second most recent message will be second and so on. I've been looking at different functions like
array_multisort
array_sort
usort
I've found other solutions online but they don't quite match what I'm looking for so does anyone know the best way to organize these chat messages?