fork download
  1. <?php
  2.  
  3. // 3
  4. function add($a, $b) {
  5. return $a + $b;
  6. }
  7. function sub($a, $b) {
  8. return $a - $b;
  9. }
  10. function mul($a, $b) {
  11. return $a * $b;
  12. }
  13. function rem($a, $b) {
  14. return $a % $b;
  15. }
  16.  
  17. // 4
  18. function mathOperation($a, $b, $operation) {
  19. switch ($operation) {
  20. case '+': return add($a, $b);
  21. case '-': return sub($a, $b);
  22. case '*': return mul($a, $b);
  23. case '%': return rem($a, $b);
  24. }
  25. }
  26. header('Content-Type: text/plain');
  27. echo mathOperation(5, 3, '+') . "\n";
  28. echo mathOperation(5, 3, '-') . "\n";
  29. echo mathOperation(5, 3, '*') . "\n";
  30. echo mathOperation(5, 3, '%') . "\n";
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
8
2
15
2