我有一个示例数组:
$a = array(
5 => 35,
16 => 22,
7 => 22,
3 => 22,
11 => 22,
9 => 27,
);
我想按值对其进行排序并记住它的键。我预期的结果是:
$a = array(
16 => 22,
7 => 22,
3 => 22,
11 => 22,
9 => 27,
5 => 35,
);
所以我的第一个想法是:asort
!好的,我做到了
asort($a);
但是不——它不只是移动5 => 35
到数组的末尾。它将我的数组更改为:
$a = array(
11 => 22,
3 => 22,
7 => 22,
16 => 22,
9 => 27,
5 => 35
);
你看 ?具有相同值的键是反向排序的。为什么 ?