1. 程式人生 > >php二維陣列按某個鍵值排序

php二維陣列按某個鍵值排序


function arrSort($arr,$field,$sort='asc'){$newArr = $sortArr = [];foreach($arr as $key=>$value){$newArr[$key] = $value[$field];}if($sort=='asc'){asort($newArr);}else if($sort=='desc'){arsort($newArr);}reset($newArr);foreach($newArr as $k=>$v){$sortArr[$k] = $arr[$k];}return $sortArr;}
function arrSort($arr,$field,$sort='SORT_DESC'){
	$newArr = array_column($arr,$field);
	return array_multisort($newArr,$sort,$newArr);
}