"zhangsan","age"=>"20",'sex'=>"男"), array("name"=>"lisi","age"=>"19",'sex'=>"男"), array("name"=>"wangwu","age"=>"18",'sex'=>"男"" name="description" /> "zhangsan","age"=>"20",'sex'=>"男"), array("name"=>"lisi","age"=>"19",'sex'=>"男"), array("name"=>"wangwu","age"=>"18",'sex'=>"男"" />

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;
}

文章来源: php多维数组排序

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:php多维数组排序