<?php /** * Created by PhpStorm. * User: 张 * Date: 2017/12/22 * Time: 11:14 */ namespace app\modules\components\helpers; class FeiArr { function array_sort($arr,$keys,$type='asc'){ $keysvalue = $new_array = array(); foreach ($arr as $k=>$v){ $keysvalue[$k] = $v[$keys]; } if($type == 'asc'){ asort($keysvalue); }elseif($type == 'desc'){ arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $k=>$v){ $new_array[$k] = $arr[$k]; } return $new_array; } function my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){ if(is_array($arrays)){ foreach ($arrays as $array){ if(is_array($array)){ $key_arrays[] = $array[$sort_key]; }else{ return false; } } }else{ return false; } array_multisort($key_arrays,$sort_order,$sort_type,$arrays); return $arrays; } }
对多维数组根据键进行排序
最新推荐文章于 2024-07-25 17:21:40 发布