How can i sort efficiently this array (recent items first) on end_time
value in PHP?
array
0 =>
array
\'value\' => int 4
You can use uasort function like this:
$arr=array();
$arr[] = array('valeu' => "4", 'end_time' => '2012-01-20T08:00:00+0000');
$arr[] = array('valeu' => "0", 'end_time' => '2012-01-21T08:00:00+0000');
$arr[] = array('valeu' => "5", 'end_time' => '2012-01-22T08:00:00+0000');
$arr[] = array('valeu' => "4", 'end_time' => '2012-01-23T08:00:00+0000');
$arr[] = array('valeu' => "7", 'end_time' => '2012-01-24T08:00:00+0000');
print_r($arr);
function cmp($a, $b) {
$ta = strtotime($a['end_time']);
$tb = strtotime($b['end_time']);
return ($ta - $tb);
}
uasort($arr, 'cmp');
print_r($arr);