Skip to content

Instantly share code, notes, and snippets.

@sagar290
Created May 2, 2019 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagar290/5041ef3dd79214400b81e26f14873785 to your computer and use it in GitHub Desktop.
Save sagar290/5041ef3dd79214400b81e26f14873785 to your computer and use it in GitHub Desktop.
Get position multiple variable
<?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