PHP中某些最高值[重复]

时间:2021-12-28 12:59:23

This question already has an answer here:

这个问题在这里已有答案:

Using this snippet:

使用此代码段:

$array = array(1,2,3,4,5,6,7,8,9,10);
echo max($array);

i get:

我得到:

10

But how to get the three highest values from this array, so the output will be:

但是如何从这个数组中获得三个最高值,所以输出将是:

10,9,8

in this order. Anybody know how to customize the max-function?

按此顺序。有谁知道如何自定义max-function?

Greetings!

问候!

1 个解决方案

#1


1  

  $array = array(1,2,3,4,5,6,7,8,9,10);
  rsort($array);
  echo $array[0]," ", $array[1], " ", $array[2];

#1


1  

  $array = array(1,2,3,4,5,6,7,8,9,10);
  rsort($array);
  echo $array[0]," ", $array[1], " ", $array[2];