I'm trying to do an exercise where I have to create a array
inside a function, and the same be accessed through an external code (example: ... php? pais = uk and show UK - London ).
The array
items are countries and capitals, eg Brazil - Brasilia, United Kingdom - uk - London, United States - us - Washington, etc.
Exercise Points:
- receive a country code, search for it in
array
, and type the name of the country. - the search has to be done in a function.
- the country code has to be passed the function as a parameter.
- the function must indicate the country and the capital.
I previously did the exercise as follows (with switch
), but with array
I'm not able to do it, it follows the code:
function paises($pais){
switch($pais){
case 'pt':
$mensagem = "Portugal";
$mensagem2 = "Lisboa";
break;
case 'br':
$mensagem = "Brasil";
$mensagem2 = "Brasilia";
break;
case 'it':
$mensagem = "Italia";
$mensagem2 = "Roma";
break;
case 'uk':
$mensagem = "Reino Unido";
$mensagem2 = "Londres";
break;
// ......
default:
echo "Nenhum país foi escolhido!";
}
}