-
Notifications
You must be signed in to change notification settings - Fork 0
/
Opdracht1-1.php
102 lines (98 loc) · 2.02 KB
/
Opdracht1-1.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<title>PHP</title>
</head>
<body>
<?php
$distances = array(
"Berlin" => array(
"Berlin" => 0,
"Moscow" => 1607.99,
"Paris" => 876.96,
"Prague" => 280.34,
"Rome" => 1181.67
),
"Moscow" => array(
"Berlin" => 1607.99,
"Moscow" => 0,
"Paris" => 2484.92,
"Prague" => 1664.04,
"Rome" => 2374.26
),
"Paris" => array(
"Berlin" => 876.96,
"Moscow" => 641.31,
"Paris" => 0,
"Prague" => 885.38,
"Rome" => 1105.76
),
"Prague" => array(
"Berlin" => 280.34,
"Moscow" => 1664.04,
"Paris" => 885.38,
"Prague" => 0,
"Rome" => 922
),
"Rome" => array(
"Berlin" => 1181.67,
"Moscow" => 2374.26,
"Paris" => 1105.76,
"Prague" => 922,
"Rome" => 0
)
);
$startIndex = "Berlin";
$endIndex = "Berlin";
$kmToMiles = 0.62;
if (isset($_POST['submit']))
{
$startIndex = stripslashes($_POST['Start']);
$endIndex = stripslashes($_POST['End']);
if (isset($distances[$startIndex][$endIndex]))
{
echo "<p>The distance from " . $startIndex . " to " .
$endIndex . " is " . $distances[$startIndex][$endIndex]
. " kilometers, or " . round(($kmToMiles *
$distances[$startIndex][$endIndex]), 2) . "miles.</p>\n";
} else
{
echo "<p>The distance from " . $startIndex . " to " .
$endIndex . " is not in the array.</p>\n";
}
}
?>
<form action="Opdracht1-1.php" method="post">
<p>Starting City:
<select name="Start"
<?php
foreach ($distances as $city => $otherCities)
{
echo "<option value='$city'";
if (strcmp($startIndex,$city)==0)
{
echo " selected";
}
echo ">$city</option>\n";
}
?>>
</select></p>
<p>Ending City:
<select name="End"
<?php
foreach ($distances as $city => $otherCities)
{
echo "<option value='$city'";
if (strcmp($endIndex,$city)==0)
{
echo " selected";
}
echo ">$city</option>\n";
}
?>>
</select></p>
<p><input type="submit" name="submit"
value="Calculate Distance"/></p>
</form>
</body>
</html>