-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question6.php
63 lines (41 loc) · 1.71 KB
/
Question6.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
<!-- In this PHP exercise, you will create an array of temperatures giving below. After
creating your array of 30 high temperatures, find the average high temp, the five
warmest high temps and the five coolest high temps. Print your findings to the browser.
Hint: the HTML character entity for the degree sign is °.
Feel free to make up the temps or gather data for your own area. Here's a list of thirty
Fahrenheit high temperatures you can use if you like:
68, 70, 72, 58, 60, 79, 82, 73, 75, 77, 73, 58, 63, 79, 78,
68, 72, 73, 80, 79, 68, 72, 75, 77, 73, 78, 82, 85, 89, 83-->
<br> ========================= LAB 3 QUESTION #6 ============================= . <br><br>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Temperatures</title>
</head>
<body>
<h1>High temperatures for spring month</h1>
<?php
$counter = 0;//vairable with sum of temperatures
$temp = array(68, 70, 72, 58, 60, 79, 82, 73, 75, 77, 73, 58, 63, 79, 78,
68, 72, 73, 80, 79, 68, 72, 75, 77, 73, 78, 82, 85, 89, 83);
//=== Looping array of temps to calculate the total sum ===\\
for ($i = 0; $i < COUNT($temp); $i++) {
$counter = $counter + $temp{$i};
}
$average = round($counter / 30); //calculating the average in array of temps
echo "The average high temperature for the month was " . $average . " F.<br>"; //displaying the average
sort($temp); //sorting temperature array
echo "<br>";
//=== Highest Temperatures ===\\
for($i = 29; $i > 24; $i--){
echo $temp[$i] . " F" . "<br>";
}
echo "<br>";
//=== Lowest Temperatures ===\\
for($i = 0; $i < 5; $i++){
echo $temp[$i] . " F" . "<br>";
}
?>
</body>
</html>