PHP Can anyone help out with this PHP assignment. Any help will be appreciated.
ID: 3719791 • Letter: P
Question
PHP
Can anyone help out with this PHP assignment. Any help will be appreciated. Thank you for your time.
Create a Web form that shows the mileage between European capitals. Use a two-dimensional associative array to store the mileage. The form should allow the user to enter a start city and an end city. Your code should then search the two dimensional for the distance from each city. For Example: A user enters Berlin to Paris. You should return "The distance from Berlin to Paris is: 879.96 km" Add the following code to the script section to declare an associative array of European cities and the distances between them in kilometers and the conversion factor for kilometers to miles: $Distances-array "Berlin"-> array ("Berlin" s) 0, "Moscow"-> 1607.99, "Paris"-> 876.96, "Prague"-> 280.34, "Rome"-> ????.67), "Moscow"-> array ("Berlin"-> 1607.99, "Moscow"-> O, "Paris"-> 2484.92, "Prague" s) ?664.04, "Rome"-> 2374.26), "Paris" -> array ("Berlin"-> 876.96, "Moscow"-> 641.31, "Paris"-> 0, "Prague" -> 885.38, "Rome"-> 105.76), "Prague" array ("Berlin" 280.34, "Moscow" > 1664.04, "Paris" 885.3, "Prague""Rome"922), Rome"- array ("Berlin" > 1181.67, "Moscow" 2374.26, "Paris" -> l105.76, "Prague" -922, "Rome" 0)) $KMtoMile s 0.62: Save the document as eudistance.php. Open the eudistance.php page a Web browser to test. Upload eudistance.php to the Web server to the module7b directory.Explanation / Answer
The variable start_city and end_city are to be given by user while submitting form. Based on that the code gives us the value of distance. Note :- The data used is dummy data.
<?php
//$start_city = $_GET['start'];
$start_city = "A";
//$end_city = $_GET['end'];
$end_city = "D";
$from_to = array(
"A" => array (
"B" => 35,
"C" => 30,
"D" => 39
),
"B" => array (
"A" => 30,
"C" => 32,
"D" => 29
),
"C" => array (
"A" => 31,
"B" => 22,
"D" => 39
)
);
// Distance value
print $from_to[$start_city][$end_city];
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.