Currently I have some multidimensional arrays that look like this
Array (
[71] => Array ( [author] => 2 [date] => 1392867376 )
[49] => Array ( [author] => 2 [date] => 1392868188 )
[75] => Array ( [author] => 14 [date] => 1392867388)
[67] => Array ( [author] => 2 [date] => 1392870805 )
)
I would like to sort them by the "date" but I have no idea how. I have tried this:
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
uasort($visited, 'cmp');
But since I have no idea, and could not find a reference on how to use the "comparison function" I'm up in space. All I've been able to find was very vague stuff. Currently this sorts by "author".
Can someone kindly explain to me how these comparison functions work (or point me to an online resource) and tell me what I need to do to sort this array by "date" - while keeping all keys intact (keys must not be changed or erased)
Many thanks for any help provided.
PS: I have tried array_multisort - It erased my keys.
try this cmp function:
It should work.