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. $op1 = "+";
  3. $op2 = "-";
  4. $op3 = "%";
  5.  
  6. if ($operation == $op1) {  
  7.     $sum1 = $a + $b;
  8.     echo (“Het resultaat is:  . $sum1 ") . PHP_EOL;
  9. } elseif ($operation == $op2) { 
  10.     $sum2 = $a - $b;
  11.     echo (“Het resultaat is: " . $sum2 ) . PHP_EOL;
  12. } elseif ($operation == $op3) {  
  13.     $sum3 = $a % $b;
  14.     echo (“Het resultaat is: ” . $sum3) . PHP_EOL;
  15. } else { 
  16.     exit(“geen geldige operatie” . PHP_EOL);
  17. } 
  18.  
  19. $a = readline(“Je eerste getal?” . PHP_EOL);
  20. if (!is_numeric($a)){
  21. } else { 
  22.     exit(“‘” . $a . “’ is geen getal” . PHP_EOL);
  23. }
  24. $b = readline(“Je tweede getal?” . PHP_EOL);
  25. if (!is_numeric($b)){
  26. } else { 
  27.     exit(“‘” . $b . “’ is geen getal” . PHP_EOL);
  28. } 
  29. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 787 Bytes
You can Share it: