php多维数组排序

先看一个简答的事例
$data=array(
    array("name"=>"zhangsan","age"=>"20",'sex'=>"男"),
    array("name"=>"lisi","age"=>"19",'sex'=>"男"),
    array("name"=>"wangwu","age"=>"18",'sex'=>"男"),
    array("name"=>"zhaoliu","age"=>"22",'sex'=>"女"),
    array("name"=>"qianqi","age"=>"21",'sex'=>"女"),
);
$sort_key=array();
foreach ($data as $key=>$value)
    $sort_key[]=$value['age'];
array_multisort($sort_key,SORT_ASC,SORT_NUMERIC,$data);
print_r($data);
定义成方法
function array_sort_more($data,$sort_order_field,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC){
    foreach($data as $val){
        $key_arrays[]=$val[$sort_order_field];
    }
    array_multisort($key_arrays,SORT_ASC,SORT_NUMERIC,$data);
    rturn $data;
}

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页