Я новичок в PHP. Я создаю программу, основанную на стране, которую вы отправляете в форме, а результат - это столица этой страны. Я столкнулся с проблемой. Я могу получить соответствующий элемент в массиве, но я не могу его вызвать, основываясь на отправке формы. Вот мой код:
<html>
<body>
<?php
$capitals = array("Algeria"=>"Algiers", "Argentina"=>"Buenos Aires", "Australia"=>"Canberra", "Belgium"=>"Minsk", "Bolivia"=>"Sucre", "Bosnia & Herzegovina"=>"Sarajevo", "Brazil"=>"Brasilia", "Bulgaria"=>"Sofia", "Cambodia"=>"Phnom Penh", "Cameroon"=>"Yaounde", "Canada"=>"Ottawa", "Chile"=>"Santiago", "China"=>"Beijing", "Colombia"=> "Bogota", "Costa Rica"=>"San Jose", "Croatia"=>"Zagreb", "Cuba"=>"Havana", "Czech Republic"=>"Prague", "Denmark"=>"Copenhagen", "Ecuador"=>"Quito", "Egypt"=>"Cairo", "Finland"=>"Helsinki", "France"=>"Paris", "Germany"=>"Berlin", "Ghana"=>"Accra", "Greece"=>"Athens", "Honduras"=>"Tegucigalpa", "Hungary"=>"Budapest", "Iceland"=>"Reykjavik", "India"=>"New Delhi", "Indonesia"=>"Jakarta", "Iran"=>"Tehran", "Iraq"=>"Baghdad", "Ireland"=>"Dublin", "Israel"=>"Jerusalem", "Italy"=>"Rome", "Jamaica"=>"Kingston", "Japan"=>"Tokyo", "Jordan"=>"Ammman", "Kazakhstan"=>"Nur-Sultan", "Kenya"=>"Nairobi", "Kosovo"=>"Pristina", "Kuwait"=>"Kuwait City", "Lebanon"=>"Beirgut", "Libya"=>"Tripoli", "Lithuania"=>"Vilnius", "Luxembourg"=>"Luxembourg", "Madagascar"=>"Antananarivo", "Malaysia"=>"Kuala Lumpur", "Maldives"=>"Male", "Malta"=>"Vakketta", "Marshall Islands"=>"Majuro", "Mexico"=>"Mexico City", "Monaco"=>"Monaco", "Morocco"=>"Rabat", "Nepal"=>"Kathmandu", "Netherlands"=>"Amsterdam", "New Zealand"=>"Wellington", "Nigeria"=>"Abuja", "North Korea"=>"Pyongyang", "Norway"=>"Oslo", "Palestine"=>"East Jerusalem", "Panama"=>"Panama City", "Paraguay"=>"Asuncion", "Peru"=>"Lima", "Philippines"=>"Manila", "Poland"=>"Warsaw", "Portugal"=>"Lisbon", "Qatar"=>"Doha", "Romania"=>"Bucharest", "Russia"=>"Moscow", "San Marino"=>"San Marino", "Saudi Arabia"=>"Riyadh", "Senegal"=>"Dakar", "Serbia"=>"Belgrade", "Sierra Leone"=>"Freetown", "Singapore"=>"Singapore", "Slovakia"=>"Bratislava", "Slovenia"=>"Ljubljana", "South Africa"=>"Bloemfontein, Cape Town, Pretoria", "South Korea"=>"Seoul", "Spain"=>"Madrid", "Sweden"=>"Stockholm",
"Switzerland"=>"Bern", "Syria"=>"Damascus", "Trinidad & Tobago"=>"Port of Spain", "Tunisia"=>"Tunis", "Turkey"=>"Ankara", "Uganda"=>"Kampala", "Ukraine"=>"Kiev", "United Arab Emirates"=>"Abu Dhabi", "United Kingdom"=>
"London", "United States"=>"Washington D.C.", "Uruguay"=>"Montevideo", "Vietnam"=>"Hanoi", "Yemen"=>"Sana'a", "Zimbabwe"=>"Harare");
foreach($capitals as $countries=>$capitals)
{
print("The capital of $countries is $capitals <br>");
}
?>
</body>
</html>
Код формы:
<html>
<body>
<form action="capitals.php" method="post">
Country: <input type = "text" name="country">
<input type="submit"><br>
</form>
</body>
</html