/
task_04.php
143 lines (111 loc) · 2.31 KB
/
task_04.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
$arr = [];
function getAllValues($postRequest) {
global $arr;
foreach ($postRequest as $value) {
if (!(preg_match("/^[0-9]+$/", $value))) {
continue;
}
array_push($arr, $value);
}
sort($arr);
return $arr;
}
$results = getAllValues($_POST);
function showMin($results) {
if (empty($results)) {
return '';
}
return $results[0] ? "<p>Min value is: $results[0] </p>" : '';
}
function showMax($results){
if (empty($results)) {
return '';
}
$len = count($results);
$max = $results[$len - 1];
return $max ? "<p>Max value is: $max </p>" : '';
}
function showAll($results) {
if (empty($results)) {
return '';
}
$allNumbs = '';
foreach ($results as $value) {
$allNumbs .= "$value ";
}
return "<p> $allNumbs </p>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
label{
width: 90px;
display: inline-block;
}
div{
margin: 5px;
}
.error{
color: red;
}
.error input, .error select, .error textarea{
border: 2px solid red;
}
</style>
</head>
<body>
<form action="" method="post">
<div>
<label for="numb1">value</label>
<input type = "text" id="numb1" name = "numb1"/>
</div>
<div>
<label for="numb2">value</label>
<input type = "text" id="numb2" name = "numb2"/>
</div>
<div>
<label for="numb3">value</label>
<input type = "text" id="numb3" name = "numb3"/>
</div>
<div>
<label for="numb4">value</label>
<input type = "text" id="numb4" name = "numb4"/>
</div>
<div>
<label for="numb5">value</label>
<input type = "text" id="numb5" name = "numb5"/>
</div>
<div>
<label for="numb6">value</label>
<input type = "text" id="numb6" name = "numb6"/>
</div>
<div>
<label for="numb7">value</label>
<input type = "text" id="numb7" name = "numb7"/>
</div>
<div>
<label for="numb8">value</label>
<input type = "text" id="numb8" name = "numb8"/>
</div>
<div>
<label for="numb9">value</label>
<input type = "text" id="numb9" name = "numb9"/>
</div>
<div>
<label for="numb10">value</label>
<input type = "text" id="numb10" name = "numb10"/>
</div>
<?= showAll($results) ?>
<?= showMin($results) ?>
<?= showMax($results) ?>
<div>
<input type = "submit" />
</div>
</form>
</body>
</html>