php 二维数组排序
function multi_compare($a, $b) { $val_arr = array( 'gold'=>'asc', 'silver'=>'desc'//还可以增加额外的排序条件 ); foreach($val_arr as $key => $val){ if($a[$key] == $b[$key]){ continue; } return (($val == 'desc')?-1:1) * (($a[$key] < $b[$key]) ? -1 : 1); } return 0; } $arr = array( array('gold'=>1, 'silver'=>2), array('gold'=>8, 'silver'=>10), array('gold'=>8, 'silver'=>8), array('gold'=>2, 'silver'=>1), ); uasort($arr, 'multi_compare'); ee($arr);