-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller1.php
39 lines (34 loc) · 868 Bytes
/
controller1.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
<?php
header("Content-Type: application/json");
$function = $_GET['function'] ?? null;
$numA = $_GET['numA'] ?? null;
$numB = $_GET['numB'] ?? null;
if (!$function || !is_numeric($numA) || !is_numeric($numB)) {
echo json_encode(["error" => "Parámetros inválidos"]);
exit;
}
$numA = (float) $numA;
$numB = (float) $numB;
switch ($function) {
case "suma":
$result = $numA + $numB;
break;
case "resta":
$result = $numA - $numB;
break;
case "multiplicacion":
$result = $numA * $numB;
break;
case "division":
$result = $numB != 0 ? $numA / $numB : "Error: División por cero";
break;
default:
$result = "Operación no válida";
break;
}
echo json_encode([
"function" => $function,
"num1" => $numA,
"num2" => $numB,
"resultado" => $result
]);