How to sort a multidimensional, associative array by time?

$posts = [ ['name'=>'David', 'time' => '2013-04-01 22:29:49'], ['name'=>'Vasya', 'time' => '2011-04-01 09:29:51'], ['name'=>'Mark', 'time' => '2013-04-02 19:29:45'], ['name'=>'Curka', 'time' => '2013-04-01 10:49:13'] ] 
  • store time in seconds, returned by time () function - woland

1 answer 1

Maybe so?

  function cmp($a, $b) { return strcmp($a["time"], $b["time"]); }; usort($posts, "cmp"); 

In addition to usort there is uasort and uksort