这是我的二维数组:
$a = array(
'6' => array(10, 5),
'5' => array(20, 7),
'40' => array(15, 9)
);
我可以简单地对它进行排序array_multisort
:
foreach ($a as $k => $r) {
$keys[$k] = $r[1];
}
array_multisort($keys, SORT_DESC, $a);
但它会清除键('6'、'5'、'40'):
Array
(
[0] => Array
(
[0] => 15
[1] => 9
)
[1] => Array
(
[0] => 20
[1] => 7
)
[2] => Array
(
[0] => 10
[1] => 5
)
)
是否array_multisort
有任何参数来保留数组键?