Rumah > Artikel > pembangunan bahagian belakang > php二维数组排序有关问题 求帮忙排序
php二维数组排序问题 求帮忙排序
现有一数组
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$a=array( 0=>array(3=>9), 1=>array(2=>9), 2=>array(6=>5), 3=>array(1=>15), 4=>array(2=>4),);
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$b=array( 0=>array(1=>15), 1=>array(3=>9), 2=>array(2=>9), 3=>array(6=>5), 4=>array(2=>4), );
$a=array( 0=>array(3=>9), 1=>array(2=>9), 2=>array(6=>5), 3=>array(1=>15), 4=>array(2=>4),);foreach($a as $v) { $r[] = current($v); $k[] = key($v);}array_multisort($r, SORT_DESC, $k, SORT_DESC, $a);print_r($a);<br><font color="#e78608">------解决方案--------------------</font><br>
……usort($a, create_function('$m, $n', 'return current($m)==current($n) ? (key($m)==key($n) ? 0 : key($m)<key : current> Array ( [1] => 15 ) [1] => Array ( [3] => 9 ) [2] => Array ( [2] => 9 ) [3] => Array ( [6] => 5 ) [4] => Array ( [2] => 4 ))/**/<div class="clear"> </div></key>