I have about 50 items in a list. I calculate their value using an algorythm and I add their value in an array.
Suppose I get this when the loop is over:
$vals = (51, 23, 77, 3, 8, 31, 17, 102, 87, (...));
Now, how can I get they keys of the 3 highest values in the array?
In the above example, I would like to get:
- 8 (key of 102)
- 9 (key of 87)
- 3 (key of 77)
PS: I don’t want to insert those datas in a DB and then select them with Order clause, I’m sure there is an easier way around.
The result is not the same you’d like to get, because arrays in php are 0-indexed