-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator_calculations.php
46 lines (38 loc) · 1.05 KB
/
calculator_calculations.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
<?php
//take in vars
$operation = $_POST['operation'];
$first_number = $_POST['first_number'];
$second_number = $_POST['second_number'];
function divide_numbers($number1,$number2){
$function_result = $number1 / $number2;
return($function_result);
}
function multiply_numbers($number1,$number2){
$function_result = $number1 * $number2;
return($function_result);
}
function subtract_numbers($number1,$number2){
$function_result = $number1 - $number2;
return($function_result);
}
function add_numbers($number1,$number2){
$function_result = $number1 + $number2;
return($function_result);
}
switch ($operation){
case '÷':
$result=divide_numbers($first_number,$second_number);
break;
case '×':
$result=multiply_numbers($first_number,$second_number);
break;
case '-':
$result=subtract_numbers($first_number,$second_number);
break;
case '+':
$result=add_numbers($first_number,$second_number);
break;
}
$return = array('first_number' => $first_number, 'second_number' => $second_number, 'operation' => $operation, 'result' => $result);
print(json_encode($return));
?>