Finish the following PHP code problem. Given the provided array of countries, ou
ID: 3847640 • Letter: F
Question
Finish the following PHP code problem. Given the provided array of countries, output the information in the array using one or more loops within a two-column HTML table. The first column will display the country name and the second column the capital city name. Make the country name a link to country.php; pass the country code (the first element in the array) as a query string with a name of code (e.g., country.php?code=AR).
$countries = array(
array("AR","Argentina","Buenos Aires"),
array("AT","Austria","Vienna"),
array("BE","Belgium","Brussels"),
array("CA","Canada","Ottawa")
);
Explanation / Answer
<html>
<head>
<title> AS YOU WISH </title>
</head>
<body>
<?php
$countries = array(
array("AR","Argentina","Buenos Aires"),
array("AT","Austria","Vienna"),
array("BE","Belgium","Brussels"),
array("CA","Canada","Ottawa")
);
foreach($countries as $country) { //go through each inner array
if ($country[0] == $_GET['code']) { //match the get parameter
echo $country[2]; //if matches, print the capital. If you want you can decorate the output
}
}
?>
</body>
<html>
You can test the code by going to
sambhasanbiswas.000webhostapp.com/other/june/country.php?code=BE
I have commented the code as far as possible tfor easy understanding. If you need any assistance, please let me know. I shall be glad to help you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.