打印结果:
- (
- [0] => Fido
- [1] => Missy
- [2] => Pluto
- )
打印结果:
- (
- [0] => 66
- [1] => 41
- [2] => 30
- [3] => 30
- [4] => 25
- [5] => 20
- [6] => 15
- [7] => 7
- [8] => 4
- [9] => 1
- )
- $arr = [
- [
- 'id'=>5,
- 'name'=>'55'
- ],
- [
- 'id'=>3,
- 'name'=>'33'
- ],
- [
- 'id'=>1,
- 'name'=>'11'
- ],
- [
- 'id'=>4,
- 'name'=>'44'
- ],
- [
- 'id'=>2,
- 'name'=>'22'
- ]
- ];
- $sort = [
- ['id' => 1],
- ['id' => 2],
- ['id' => 3],
- ['id' => 4],
- ['id' => 5]
- ];
打印结果:
多字段排序
二维数组 先根据字段A排序 如果A一样通过字段B排序 如果AB都一样 就按C字段排序
思路:
1.先搜集要排序的字段的值分别组合成一个新的数组
2.在用array_multisort 根据要排序的字段值 按先后进行排序就行
$order_data-要排序的数组
- //二位数组根据多个字段排序
- foreach ($order_data as $key => $row ){
- $inv_total_amount_order[$key] = $row ['inv_total_amount'];
- $last_time_order[$key] = $row ['last_time'];
- $persion_year_inv_total_order[$key] = $row['persion_year_inv_total'];
- $user_reg_time_order[$key] = $row ['user_reg_time'];
- }
- array_multisort($persion_year_inv_total_order,SORT_DESC,$last_time_order, SORT_ASC,$inv_total_amount_order, SORT_DESC, $user_reg_time_order,SORT_ASC,$order_data);
一条评论
好文章!666,学习了