Jump to content

Recommended Posts

<?php // Place your work here, between the opening and closing tags.

/*******************************************************************
The code below initializes three (3) arrays:

1. $countries is a list of countries. 
2. $un_secretaries contains the names of current and former
   secretaries-general of the UN; their native country is the key 
   to the array.
3. $nobel_winners contains some of the countries which have 
   produced Nobel Peace Prize winners some time in the last 20 
   years.

Your job is to loop through the $countries array and determine...
1. ...whether each country has produced a UN 
   secretary-general; if so, print his name;
2. ...whether each country has produced a Nobel Peace
   prize winner. If so, print a statement that says so.
*******************************************************************/
$countries = array( 
    'China', 'Costa Rica',
    'Austria', 'Australia', 
    'Ghana', 'Guatamala',
    'Canada', 'South Korea',
    'Iran', 'Ethopia',
    'Japan', 'Myanmar',
    'France', 'Finland'
);

// Initialize array with UN secretaries-general.
$un_secretaries = array(
    'South Korea' => 'Ban Ki-moon',
    'Ghana' => 'Kofi A. Annan',
    'Egypt' => 'Boutros Boutros-Ghali',
    'Peru' => 'Javier Perez de Cuellar',
    'Austria' => 'Kurt Waldheim',
    'Myanmar' => 'U Thant',
    'Sweden' => 'Dag Hammarskjöld',
    'Norway' => 'Trygve Lie'
);

// Initialize array with some countries that have produced
// Nobel Peace prize winners.
$nobel_countries = array( 
    'Finland', 'Bangladesh',
    'Kenya', 'Iran',
    'South Korea', 'Guatemala',
    'Myanmar', 'Costa Rica'
);

// Start here:

?>

<?php
foreach ($countries as $country){
if(array_key_exists($country, $un_secretaries)){
	echo $un_secretaries[$country] . '<br>';
}
}

foreach ($countries as $country){
if(array_key_exists($country, $nobel_countries)){
	$country . ' has produced nobel peace prize winners.<br>';
}
}
?>

at the age of 60

 

Your profile says 55.  The key to getting people to believe you when you lie, is to remain consistent. 

 

Also, real adults learn to actually ask questions instead of make vague subjects and post nothing but code, no question or nothin'...not even going to point out how the comments in it are screaming "homework." 

 

 

MadTechie I think you are really mad. but not its 03:25 I'll go to bed - wanted to watch the stars but the MadTechie is well mad.

 

Thanks HotDaWg - will let you know 10 hours if the code is working - in the meantime good night or good morning.

<?php
foreach ($countries as $country){
if(array_key_exists($country, $un_secretaries)){
	echo $un_secretaries[$country] . '<br>';
}
}

foreach ($countries as $country){
if(array_key_exists($country, $nobel_countries)){
	$country . ' has produced nobel peace prize winners.<br>';
}
}
?>

 

Thanks its solved - you are a star HoTDaWg

Well my problems have not been solved yet - any help here is part of the code - up to now he only prints out the name of the prize winners but I would like the countries to be printed as well . here is the code

 

<?php // Printout

foreach ($countries as $country){
   if(array_key_exists($country, $un_secretaries)){
      echo $un_secretaries[$country] . '<br>';
   }
}

foreach ($countries as $country){
   if(array_key_exists($country, $nobel_countries)){
      echo $nobel_countries[$country] . ' has produced nobel prize winners.<br>';
   }
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.