Output repeating data

I am working on an assignment that displays the EU capitals for each country in bold. So far the code I am using matches with the exception that the data repeats 24-25 times. What am I missing?

[php]

EU Country Array

Countries in the European Union and their Capitals

Sort by the name of the

Country

<?php

$EU = array(
“Italy”=>“Rome”,
“Luxembourg”=>“Luxembourg”,
“Belgium”=> “Brussels”,
“Denmark”=>“Copenhagen”,
“Finland”=>“Helsinki”,
“France” => “Paris”,
“Slovakia”=>“Bratislava”,
“Slovenia”=>“Ljubljana”,
“Germany” => “Berlin”,
“Greece” => “Athens”,
“Ireland”=>“Dublin”,
“Netherlands”=>“Amsterdam”,
“Portugal”=>“Lisbon”,
“Spain”=>“Madrid”,
“Sweden”=>“Stockholm”,
“United Kingdom”=>“London”,
“Cyprus”=>“Nicosia”,
“Lithuania”=>“Vilnius”,
“Czech Republic”=>“Prague”,
“Estonia”=>“Tallin”,
“Hungary”=>“Budapest”,
“Latvia”=>“Riga”,
“Malta”=>“Valetta”,
“Austria” => “Vienna”,
“Poland”=>“Warsaw”) ;

asort($EU) ;
foreach($EU as $country => $capital) {
echo “

    ”;
    foreach ($EU as $k => $v) {
    echo “
  • The capital of $k is $v

  • ”;
    }
    echo “
”;
}
?> [/php]

You have an extra unnecessary foreach. Replace your entire foreach block with the code below.

[php] foreach($EU as $country => $capital) {
echo “

    ”;
    echo “
  • The capital of $country is $capital

  • ”;
    echo “
”;
}[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service