Webgirl Posted August 14, 2009 Share Posted August 14, 2009 <?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: ?> Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/ Share on other sites More sharing options...
MadTechie Posted August 14, 2009 Share Posted August 14, 2009 Sounds like homework! Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897731 Share on other sites More sharing options...
Webgirl Posted August 14, 2009 Author Share Posted August 14, 2009 at the age of 60 Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897732 Share on other sites More sharing options...
HoTDaWg Posted August 14, 2009 Share Posted August 14, 2009 <?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>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897757 Share on other sites More sharing options...
.josh Posted August 14, 2009 Share Posted August 14, 2009 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." Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897760 Share on other sites More sharing options...
MadTechie Posted August 14, 2009 Share Posted August 14, 2009 I was going to say, 60 year old can still get homework.. theirs lots of course people can take at any age! Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897764 Share on other sites More sharing options...
Webgirl Posted August 14, 2009 Author Share Posted August 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897781 Share on other sites More sharing options...
Webgirl Posted August 14, 2009 Author Share Posted August 14, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897782 Share on other sites More sharing options...
MadTechie Posted August 14, 2009 Share Posted August 14, 2009 MadTechie I think you are really mad. Thanx Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-897790 Share on other sites More sharing options...
Webgirl Posted August 14, 2009 Author Share Posted August 14, 2009 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>'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170186-need-help-looping-thru-an-array-and-exctracting-something/#findComment-898458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.