如何通过降序值对多维数组进行排序?我已经想出了这个但它没有用。
$data = [
0 => array(
"Date" => "2016-05-04 12:00:00"
),
1 => array(
"Date" => "2016-05-04 10:00:00"
)
]
PHP
uasort($data, function($a, $b) {
return $a['Date'] - $b['Date'];
});
答案 0 :(得分:0)
试试这个:
$data = array(
'0' => array(
"Date" => "2016-05-04 12:00:00"
),
'1' => array(
"Date" => "2016-05-04 10:00:00"
)
);
function date_compare($a, $b)
{
$t1 = strtotime($a['Date']);
$t2 = strtotime($b['Date']);
return $t1 - $t2;
}
usort($data, 'date_compare');
print '<pre>';print_r($data);
exit;
答案 1 :(得分:0)
试试这个:
uasort($data, function($a, $b) {
$t1 = strtotime($a['Date']);
$t2 = strtotime($b['Date']);
return $t2 - $t1;
});