1
I’m trying to do an exercise where I have to create a array
within a function, and the same be accessed through an external code (example: ...php? parents=uk and show United Kingdom - London).
The items of array
are countries and capitals, example: Brazil - br - Brasilia, United Kingdom - uk - London, United States - us - Washington, etc.
Points of the exercise:
- receive a country code, search it on
array
and write the name of the country. - the search has to be performed in a function.
- the country code has to be passed the function as parameter.
- the function has to indicate the country and the capital.
I previously did the exercise as follows (with switch
), but with a array
I’m not getting it, follow 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!";
}
}
What result do you expect to have? if possible post the code in the question instead of images!
– stderr
Basically I am doing some exercises of php, I am learning and the exercise asks the following: https://s32.postimg.org/hg1fj72wl/exercicio.jpg I can’t post the code, because I am not at home at the moment, only at night! Thank you! @zekk
– Mario Caeiro