fork(1) download
  1. <?php
  2.  
  3. function generator($start, $step) {
  4. if (func_num_args() == 1) {
  5. $step = 1;
  6. }
  7.  
  8. return function() use (&$start, $step) {
  9. return $start += $step;
  10. };
  11. }
  12.  
  13. $counter = generator(2, 2);
  14.  
  15. echo $counter();
  16. echo $counter();
  17. echo $counter();
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
468