lol.. yes, it does sound like a homework assignment..
Like Puckdropper said, its better to update the SQL rather than PHP. If you're set on PHP (I dont want to do your homework for you

) however its a very simple task.
Heres the link to php documentation on the array notation/syntax:
http://php.net/manual/en/language.types.array.php
You can use the array notation, or array functions (
http://php.net/array) to create an array.
Your array should be a simple 1 dimensional array (each value has a single key) that links either:
1) The primary key of countries_master.value with the corresponding 2 digit ISO country code, or
2) The 3 Digit country code field in countries_master.value with the corresponding 2 Digit ISO country code
Knowing the key in an array means you can extract the corresponding value using $array[$key];
So if your array has the 3 digit county codes as index, then $array[$countycode3digits] should retrieve the 2 digit country code value.
It's good practice to first check if the key exists before trying to retieve an array value using the key.
The function to check if a key exists in an array can be found in the array function list:
http://php.net/array