php - Best way to sort a big array by a key -
i have big array lots of datas, here can have example :
is example have 1 item [0]
.
i need sort array key date
in last_message
. (more in first)
in date
have format : "2014-04-23t14:59:53+0200"
do have idea me ? don't want foreach think there better.
thanks !
this code :
uasort($arrayc, function ($a, $b) { if ($a == $b) { return 0; } return (strtotime($a['last_message']->date) < strtotime($b['last_message']->date)) ? -1 : 1; });
but there no effect on array..
you can use http://www.php.net/manual/en/function.uasort.php , provide custom function compares date.
this this:
function cmp($a, $b) { if ($a == $b) { return 0; } return (strtotime($a['last_message']['date']) < strtotime($b['last_message']['date'])) ? -1 : 1; } uasort($array, 'cmp');
Comments
Post a Comment