Question: I tried to get the 2nd highest value from an array and I simply want to know if it is possible to do something like MAX -1 OR I absolutely need to sort by table and the 2nd highest value 

```
private function max_key($array) {
    foreach ($array as $key => $val) {
    if ($val == max($array))  return $key;
    }
    }

```

Answer: 
The best way is to use a qsort algorithm ( more readable code, less debugging ). If your array/table is very huge ( and so also qsort can create reasonable performance problem to your code ), you can probably perform a linear search storing in 2 vars the "max" and "max-1" elements: not too much expensive to do, but you need to understand if that work can give you real advantage.

Another aproach could be try to keep sorted your array directly at its source ( SQL / DB table ).
I don't think you will find a MAX - 1 function. Probably need to do a type of sort, then take the second position in the sorted array.