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

后端 未结 5 811
醉梦人生
醉梦人生 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:14

    $n = array(100,90,150,200,199,155,15,186);
    arsort($n);
    
    $x = 0;
    while (++$x <= 3)
    {
        $key = key($n);
        $value = current($n);
        next($n);
        echo "Key : " . $key . " Value  : " . $value . '
    ' ; }

提交回复
热议问题