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,
Try this:
$n = array(100,90,150,200,199,155,15,186); rsort($n); $top3 = array_slice($n, 0, 3); echo 'Values: '; foreach ($top3 as $key => $val) { echo "$val\n"; } echo ''; echo 'Keys: '; foreach ($top3 as $key => $val) { echo "$key\n"; }
Output:
Values: 200 199 186 Keys: 0 1 2