首页 > 代码库 > PHP二维数组根据某个键名排序

PHP二维数组根据某个键名排序

$result = array(
    array(
           "amount": "11.00",
           "date": "2015.10.10",
           "title": "缴纳会员费"
       ),
    array(
           "amount": "11.00",
           "date": "2016.10.10",
           "title": "缴纳会员费"
       )
  );
$sort = array(
‘direction‘ => ‘SORT_DESC‘, //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
‘field‘ => ‘date‘, //排序字段
);
$arrSort = array();
foreach($result AS $keys=> $row){
foreach($row AS $key=>$value){
$arrSort[$key][$keys] = $value;
}
}
if($sort[‘direction‘]){
array_multisort($arrSort[$sort[‘field‘]], constant($sort[‘direction‘]), $result);
}
print_r($result);

PHP二维数组根据某个键名排序