I have multidimensional array in PHP. Something like
$mylist = array(
array('ID' => 1, 'title' => 'Hello', 'datetime' => '2014-05-05 12:08 PM'),
array('ID' => 2, 'title' => 'Amazing Pic', 'datetime' => '2014-05-06 11:08 PM'),
array('ID' => 3, 'title' => 'Style', 'datetime' => '2014-05-02 9:08 PM'),
array('ID' => 4, 'title' => 'Hello World', 'datetime' => '2014-05-01 5:08 PM')
);
My question is how do I sort by title and datetime? I spent quite some time searching on this. But I just found sort by two columns but with the same data type. I am now struggling to do this because I believe mine involve strtotime() function as this involves time.
This is what I have at this moment
function querySort ($x, $y) {
return strcasecmp($x['title'], $y['title']);
}
function cmp($a, $b){
$ad = strtotime($a['datetime']);
$bd = strtotime($b['datetime']);
return ($ad-$bd);
}
usort($mylist , 'querySort');
usort($mylist , 'cmp');
Could anyone help me on how to achieve this?