"Daniel Hsu", "AB" => "Chao Hsu Lin", "AC" => "Jack Venberg", "AD" => "Sandy Yang", "AE" => "Ann Shan", "AF" => "Manchen Jin", "AG" => "Hudson Gilmore", "AH" => "Manny Munoz", "AI" => "Will Bigelow", "AJ" => "Zach Wu", "AK" => "Olga Andreeva", "AL" => "Tal Wolman", "AM" => "Louis Maliyam", "AN" => "Valerie Remaker", "AO" => "Mark Guan", "AP" => "Kyle Roland", "AQ" => "Sven Hansen", "AR" => "Kevin Pham"); # Part 1: Finish this web service to take a GET parameter called 'section' # and print out the TA name for that section. if (isset($_GET["section"])) { $section = strtoupper($_GET["section"]); if (isset($tas[$section])) { echo $tas[$section]; } else { set_error("Passed section code not found"); } } else if (isset($_GET["name"])) { # Part 2: Finish this web service to take a GET parameter called 'name' # and print out the section for the TA with the value passed as their first name. $name = $_GET["name"]; foreach ($tas as $key => $value) { # explode is a function which "explodes" a string based on a delimiter, returning an array of the pieces $firstname = explode(" ", $value)[0]; if (strtolower($name) === strtolower($firstname)) { die("{$key}\n"); # we found a TA with the first name! Print their section code. } } # If we've reached here, we've looped through all tas # and haven't found the name set_error("No TA found with given first name"); } else { set_error("Missing one of required 'section' or 'name' GET parameters."); } # Helper method to set and print a 400 Invalid Request error # @param $msg {String} - error message to print details of invalid request function set_error($msg) { header("HTTP/1.1 400 Invalid Request"); echo $msg; } ?>