how to get top 3 values in php array and their index

后端 未结 5 813
醉梦人生
醉梦人生 2021-01-18 21:45

I want to get the highest value, the second highest value and the third highest value

For example, I have an array like:

$n = array(100,90,150,200,199,

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 22:20

    Easier I would think:

    arsort($n);
    $three = array_chunk($n, 3, true)[0];
    //or
    $three = array_slice($n, 0, 3, true);
    

提交回复
热议问题