html head head body form method POST Write number one input type text

 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
<html>
<head>
</head>
<body>
<form method="POST">
<p> Write number one</p>
<input type="text" name="numOne">
<p> Write number two</p>
<input type="text" name="numTwo">
<p> Select operator</p>
<select name="operator">
<option value="+" >+</option>
<option value="-">-</option>
</select>
<input type="submit">
</form>
</body>
</html>
<?php
function operation(int $numOne ,int $numTwo,string $name){
return $name($numOne,$numTwo);
}
function add(int $numOne ,int $numTwo){
return $numOne + $numTwo;
}
function sub(int $numOne ,int $numTwo){
return $numOne - $numTwo;
}
if (!empty($numTwo) && !empty($numTwo) && !empty($operator)) {
if ($_POST['operator'] == '+') {
echo operation($_POST['numOne'], $_POST['numTwo'], "add");
} elseif ($_POST['operator'] == '-') {
echo operation($_POST['numOne'], $_POST['numTwo'], "sub");
}
} else {
echo "Choose all parameters ";
}