Created
October 27, 2019 19:34
-
-
Save BlakeStevenson/cf974f482371aee67edb98c6edac1ac4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function school_roster($id) { | |
$url = "https://www.myutr.com/api/v1/club/$id/school"; | |
// Initialize a CURL session. | |
$ch = curl_init(); | |
// Return Page contents. | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
//grab URL and pass it to the variable. | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$result = curl_exec($ch); | |
// decode JSON | |
$apiresult = json_decode($result, true); | |
// create arrays with player names and ratings stored by user id | |
foreach($apiresult['roster'] as $player) { | |
$playerNames[$player['id']] = $player['displayName']; | |
$ratings[$player['id']] = $player['singlesUtr']; | |
} | |
// sort ratings greatest to least | |
arsort($ratings); | |
// create new roster with names + ratings sorted properly. | |
foreach($ratings as $id => $rating) { | |
$roster[] = array( | |
"name" => $playerNames[$id], | |
"rating" => $ratings[$id] | |
); | |
} | |
// add school name to output | |
$finalresult = array( | |
"schoolName" => $apiresult['displayName'], | |
"roster" => $roster, | |
); | |
return $finalresult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment