Created
May 2, 2019 17:03
-
-
Save sagar290/38d85fbe6f8dede85dc8dab7d9766695 to your computer and use it in GitHub Desktop.
get user position (best)
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 | |
$user_id = 1; //assigned user id in $user id variable | |
$scores= Score::orderBy('score', 'desc')->orderBy('time', 'asc')->pluck('user_id')->toArray(); // get only user id in sorted ordered in term of score and time | |
$flip = array_flip($scores); // flip array index to value value to index | |
return $flip[(string)$user_id]+1; // add 1 because it will return index value | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment