-5

我有这个数组...

Array (
[1168] => 46
[6973] => 27
[4585] => 24
[1224] => 23
[2010] => 20
[7514] => 19
[1167] => 17
[8349] => 7
[2476] => 7
[5313] => 7
[1208] => 2
)

我需要在前一个数组中获取三个具有最高值的键(作为值):

Array (
[0] => 1168
[1] => 6973
[2] => 4585
)
4

2 回答 2

2

数组是否总是按降序排序?如果没有,你需要arsort($arr)先:

$highest_keys = array_keys(array_slice($arr, 0, 3));
于 2012-05-26T01:04:36.173 回答
1

编辑:

$a = array('foo' => 3, 'bar' => 2, 'fuz' => 1, 'baz' => 0);
$k = array_keys(array_slice($a, 0, 3));
print_r($k);

键盘

于 2012-05-26T01:14:30.367 回答