-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex6.php
93 lines (76 loc) · 2.22 KB
/
ex6.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
<html>
<head>
<style>
div{
margin-top: 30px;
margin-left: 30px;
}
button {
margin: 10px 0 0 30px;
width: 120px;
height: 30px;
}
input {
width: 80px;
height: 25px;
margin-right: 15px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<div>
<form action="" method="GET">
<h2>Enter 10 numbers: </h2>
<input type="number" step= 0.01 name="n0">
<input type="number" step= 0.01 name="n1"> <br>
<input type="number" step= 0.01 name="n2">
<input type="number" step= 0.01 name="n3"> <br>
<input type="number" step= 0.01 name="n4">
<input type="number" step= 0.01 name="n5"> <br>
<input type="number" step= 0.01 name="n6">
<input type="number" step= 0.01 name="n7"> <br>
<input type="number" step= 0.01 name="n8">
<input type="number" step= 0.01 name="n9"> <br>
<button type="submit">Sumbit</button>
</form>
</div>
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['n0'])) {
$tab = [];
for ($i = 0; $i < 10; $i++) {
$x = $_GET["n" . $i];
$tab[$i] = $x;
}
$_SESSION['tab'] = $tab;
echo '<div style="margin-left:15px">
<form action="" method="GET">
<h2>Enter a number to check:</h2>
<input type="number" step="0.01" name="n">
<button type="submit">Check Number</button>
</form>
</div>';
}
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['n'])) {
$tab = $_SESSION['tab'];
function myFunction($tab){
for ($i = 0; $i < 10; $i++){
if ($tab[$i] == $_GET["n"]){
return true;
}
}
return false;
}
echo("<br>") ;
print_r($tab);
echo("<br><br>") ;
if (myFunction($tab) == true){
echo "The number " . $_GET["n"] . " is in the array." ;
} else {
echo "The number " . $_GET["n"] . " is not in the array." ;
}
}
?>
</body>
</html>