View Single Post
07-16-2005, 04:08 PM
#4
opserty is offline opserty
Status: I love this place
Join date: Jan 2005
Location: UK, Birmingham
Expertise:
Software:
 
Posts: 606
iTrader: 0 / 0%
 

opserty is on a distinguished road

Send a message via MSN to opserty

  Old

(sketchie) Could you not just use for(each) and an if statement to check? rather then all that code you've put there?

PHP Code:
<?php

$country 
$_POST['country'];
$capital=array(
"UK" => "London",
"France" => "Paris",
"Germany" => "Berlin",
"Spain" => "Madrid"
"Etc" 
=> "Etc"
); 

foreach (
$capital as $k => $v
{
    if(
$country == $k)
    {
        echo 
"The Capital of ".$k." is ".$v;
    }
}
?>
For Muhammad: This basically cycles through each of the countries finds a match and the echos the capital.

P.S. (sketchie) You don't know your countries and capitals London is the capital of the UK