Rank function (Like MS Excel)


I am curious to know if there is a easy way to rank values using php. I have googled for a while and can’t seem to turn up any relevant results. I have a few dynamic values, that I need to rank by the highest value.

<th>Total Call Attempts</th><th>Rank</th>

Do any of you have any ideas? Any help is appreciated.


Define rank.


You could try using rsort() or some similar function if you have the information in an array…


By rank I would like to take a range of values from the db, and assign a rank.
For example
Let’s say i have a field called Total Call AttemptsI would like to rank by the amount of call attempts.

Total Call Attempts | Rank

1000 | 1
900 | 2
800 | 3

I hope this clarifies things. Thanks in advance.


Ahhh. Look at the SQL keywords ORDER BY. If you are using MySQL see


Order by would work if the “Rank” field existed in the database, however it does not. I would like to (hopefully) use a php function to define rank dynamically.
I hope this helps.


Guess you could use the max() mathmatical function.

I would put it all into an array and use one of the array sorting functions to sort it.

Manual -> Search -> functions ->type array (will give you all the array functions - right before user comments - so you can also see how to create one) Or http://www.php.net/manual/en/ref.array.php :)