fork(1) download
  1. <?php
  2. $operations = array('+', '-', '*', '%');
  3. $functions = array();
  4. foreach ($operations as $op) {
  5. $functions[$op] = create_function('$a, $b', 'return $a ' . $op . ' $b;');
  6. }
  7. function mathOperation($a, $b, $operation) {
  8. global $functions;
  9. // return call_user_func($functions[$operation], $a, $b);
  10. return $functions[$operation]($a, $b);
  11. }
  12.  
  13. header('Content-Type: text/plain');
  14. foreach (array('+', '-', '*', '%') as $operation) {
  15. echo mathOperation(5, 3, $operation) . "\n";
  16. }
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
8
2
15
2