Created
May 2, 2019 16:30
-
-
Save sagar290/5041ef3dd79214400b81e26f14873785 to your computer and use it in GitHub Desktop.
Get position multiple variable
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')->orderBy('time', 'asc')->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