Last active
May 2, 2019 16:06
-
-
Save sagar290/910ee08c4ec02248dddad1c5e24d3e00 to your computer and use it in GitHub Desktop.
get user rank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$scores = Score::orderBy('score', 'desc')->get(); // get the sorted data | |
$user_id = 1; // we assigned the user id in $user_id variable | |
$output = array_search($user_id, array_column($scores, 'user_id')); // get he user index value by array search. | |
$position = $output + 1; // add 1 because its start with 0 index | |
return $position |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment