fork(4) download
  1. <?php
  2.  
  3. echo "Using echo:\n";
  4.  
  5. function add1($x, $y){
  6. $total = $x + $y;
  7. echo $total;
  8. }
  9.  
  10. $result = add1(2, 2);
  11.  
  12. echo "2 + 2 = ", $result, "\n";
  13.  
  14. echo "\n\n";
  15. echo "Using return:\n";
  16.  
  17. function add2($x, $y){
  18. $total = $x + $y;
  19. return $total;
  20. }
  21.  
  22. $result = add2(2, 2);
  23.  
  24. echo "2 + 2 = ", $result, "\n";
  25.  
  26. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Using echo:
42 + 2 = 


Using return:
2 + 2 = 4