calculator - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of calculator.php
- <?php
- $getal_1 = readline("Eerste getal?" . PHP_EOL);
- $getal_2 = readline("Tweede getal?" . PHP_EOL);
- if (!is_numeric($getal_1)) {
- exit("Het eerste getal was ongeldig!");
- } else if (!is_numeric($getal_2)) {
- exit("Het tweede getal is ongeldig!");
- }
- $var1 = '$getal_1';
- echo("Variable: ".$var);
- echo"\nAfter the intval() function...";
- $int_val= intval($var);
- echo "\nInteger value: ".$int_val2;
- $var2 = '$getal_2';
- echo("Variable: ".$var);
- echo"\nAfter the intval() function...";
- $int_val= intval($var);
- echo "\nInteger value: ".$int_val2;
- $operator = readline('Welke operatie wil je uitvoeren? (+, -, %) ' . PHP_EOL);
- if ($operator === ("+")) {
- $sum1 = $getal_1 + $getal_2;
- echo "Uw resultaat is: " . $sum1;
- } else if ($operator === ("-")) {
- $sum2 = $getal_1 - $getal_2;
- echo "Uw resultaat is: " . $sum2;
- } else if ($operator === ("%")) {
- $sum3 = $getal_1 % $getal_2;
- echo "Uw resultaat is: " . $sum3;
- }
- ?>