Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-Type: application/json');
  4.  
  5. $aResult = array();
  6.  
  7. if( !isset($_POST['functionname']) ) { $aResult['error'] = 'No function name!'; }
  8.  
  9. if( !isset($_POST['arguments']) ) { $aResult['error'] = 'No function arguments!'; }
  10.  
  11. if( !isset($aResult['error']) ) {
  12.  
  13. switch($_POST['functionname']) {
  14. case 'add':
  15. if( !is_array($_POST['arguments']) || (count($_POST['arguments']) < 1) ) {
  16. $aResult['error'] = 'Error in arguments!';
  17. }
  18. else {
  19. $aResult['result'] = add(floatval($_POST['arguments'][0]));
  20. }
  21. break;
  22.  
  23. default:
  24. $aResult['error'] = 'Not found function '.$_POST['functionname'].'!';
  25. break;
  26. }
  27.  
  28. }
  29. echo json_encode($aResult);
  30.  
  31. function add($a){
  32. return $a;
  33. }
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement