Hello Reader's If you are developing the project related to gaming and you want make the Ranking of your users, Then this blog is very helpful to you.
Suppose you have a criteria of total wins by a user on which the ranking will assign. You can not make the mysql order by syntax because same number of wins count of multiple user should make their same ranking.
Now we'll make the ranking according the count of wins by every user. And its code will go like this:-
// now just use the original array and lookup the rankings for each value
$return = array();
foreach($ranking as $key=>$value)
$rankedValue = array();
$rankedValue['id'] = $key;
$rankedValue['value'] = $value;
$rankedValue['rank'] = array_search($value, $rankings) + 1;
$return = $rankedValue;
foreach($return as $getPlayerRank)
if($getPlayerRank['id'] == $userId)
$data["rank"] = $getPlayerRank['rank'];