我想按其中一列对二维数组进行排序...例如:
$a = array(
'user4' => array('name' => 'u4', 'payment' => 1000, 'time' => 5000),
'user2' => array('name' => 'u2', 'payment' => 2000, 'time' => 5000),
'user3' => array('name' => 'u3', 'payment' => 2000, 'time' => 3000),
);
我想按payment
( DESC
) 和time
( ASC
) 对其进行排序。所以排序后的数组应该是这样的:
$a = array(
'user3' => array('name' => 'u3', 'payment' => 2000, 'time' => 3000),
'user2' => array('name' => 'u2', 'payment' => 2000, 'time' => 5000),
'user4' => array('name' => 'u4', 'payment' => 1000, 'time' => 5000),
);
怎么做?谢谢,
我找到了解决方案:
foreach ($a as $key => $row) {
$payment[$key] = $row['payment'];
$time[$key] = $row['time'];
}
array_multisort($payment, SORT_DESC, $time, SORT_ASC, $a);