Skip to content

Instantly share code, notes, and snippets.

@flowerains
Last active December 14, 2015 04:31
Show Gist options
  • Save flowerains/7a3e0f0961925867c0ca to your computer and use it in GitHub Desktop.
Save flowerains/7a3e0f0961925867c0ca to your computer and use it in GitHub Desktop.
二维数组排序 sort
<?php
//指定数组以$keys键值排序
function array_sort($array,$keys,$type='asc'){
//$array为要排序的数组,$keys为要用来排序的键名,$type默认为升序排序
$keysvalue = $new_array = array();
foreach ($array as $k=>$v){
$keysvalue[$k] = $v[$keys];
}
if($type == 'asc'){
asort($keysvalue);
}else{
arsort($keysvalue);
}
reset($keysvalue);
foreach ($keysvalue as $k=>$v){
$new_array[$k] = $array[$k];
}
return $new_array;
}
$hot_cat = array_sort($hot_cat,'count','desc'); //此处对数组进行降序排列</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment