Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $score = array(
- array(
- "uid" => 122, //uid
- 100, //a
- 50 //b
- ),
- array(
- "uid" => 230, //uid
- 150, //a
- 20 //b
- ),
- );
- $a = array(); // new array for type a scores
- $b = array(); // new array for type b scores
- $ab = array();// new array for type ab scores
- //We want to add all user scores to the appropriate arrays
- foreach($score as $k => $v) {
- $a[$score[$k]["uid"]] = $score[$k][0]; //Place all A scores into array with users UID as key
- $b[$score[$k]["uid"]] = $score[$k][1]; //Place all A scores into array with users UID as key
- $ab[$score[$k]["uid"]] = $score[$k][0] + $score[$k][1]; //Place A+B scores into array with users UID as key
- }
- arsort($a); //Sort a
- arsort($b); //Sort B
- arsort($ab);//Sort A+B
- print("User search: 230 \n A:");
- echo array_search("230",array_keys($a)) + 1; //Find user position in array and add 1
- print("\n B:");
- echo array_search("230",array_keys($b)) + 1; //Find user position in array and add 1
- print("\n A+B:");
- echo array_search("230",array_keys($ab)) + 1; //Find user position in array and add 1
- ####################Expected Output#####################
- ### User search: 230 #
- ### A:1 #
- ### B:2 #
- ### A+B:1 #
- ########################################################
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement