使数组按指定的KEY值排序
时间:2021-07-01 10:21:17
帮助过:99人阅读
- function array_sort($arr,$keys,$orderby='asc'){
- $keysvalue = $new_array = array();
- foreach ($arr as $k=>$v){
- $keysvalue[$k] = $v[$keys];
- }
- if($orderby== 'asc'){
- asort($keysvalue);
- }else{
- arsort($keysvalue);
- }
- reset($keysvalue);
- foreach ($keysvalue as $k=>$v){
- $new_array[] = $arr[$k];
- }
- return $new_array;
- }
|