可能重复:
how to sort a multidemensional array by an inner key
How to sort a multidimensional array by a certain key?
我希望我的数组按日期asc排序,怎么办?
<?php
//how to resort a array by key 'date'?
$arr=array(
array(
'name'=>'a',
'date'=>'2012-10-21 18:00:00'
),
array(
'name'=>'x',
'date'=>'2013-10-21 18:00:00'
),
array(
'name'=>'d',
'date'=>'2011-10-21 18:00:00'
)
);
?>
答案 0 :(得分:3)
function sort_by_date($a, $b) {
return( $a['date'] < $b['date'] ? -1 : ($a['date'] > $b['date']) ? 1 : 0 );
}
usort($arr, 'sort_by_date');