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.



Your result can be seen below.

Result of php executing





Full code of calculator.php

  1. $operation = readline(“Welke operatie wil je uitvoeren? (+, -, %));
  2. if ($operation == (+)) {
  3.     echo (“Optellen”) . PHP_EOL;
  4. } elseif ($operation == (-)) {
  5.     echo (“Aftrekken”) . PHP_EOL;
  6. } elseif ($operation == (%)) {
  7.     echo (%) . PHP_EOL;
  8. }
  9. $a = readline(“Je eerste getal?” . PHP_EOL);
  10. if (!is_numeric($a)){
  11.     exit(“‘” . $a . “’ is geen getal?” . PHP_EOL);
  12. }
  13. $b = readline(“Je tweede getal?” . PHP_EOL);
  14. if (!is_numeric($b)){
  15.     exit(“‘” . $b . “’ is geen getal” . PHP_EOL);
  16. }
  17. if ($operation == (+)) {
  18.     $sum1 = $a + $b;
  19.     echo (“Het resultaat is: ” . $sum1) . PHP_EOL;
  20. } elseif ($operation == (-)) {
  21.     $sum2 = $a - $b;
  22.     echo (“Het resultaat is: ” . $sum2) . PHP_EOL;
  23. } elseif ($operation == (%)) {
  24.     $sum3 = $a % $b;
  25.     echo (“Het resultaat is: ” . $sum3) . PHP_EOL;
  26. }
  27. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 919 Bytes
You can Share it: