fork(2) download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. function xrange($start,$end,$reset=false) {
  6. static $position = NULL;
  7.  
  8. if($position == NULL || $reset) {
  9. $position = 0;
  10. }
  11.  
  12. $value = $position+$start;
  13.  
  14. if($value <= $end) {
  15. return array($position++, $value);
  16. } else {
  17. return array();
  18. }
  19. }
  20.  
  21. while(list($key, $value) = xrange(1,10)) {
  22. echo "$key => $value\n";
  23. }
  24.  
Success #stdin #stdout #stderr 0.02s 24400KB
stdin
Standard input is empty
stdout
0 => 1
1 => 2
2 => 3
3 => 4
4 => 5
5 => 6
6 => 7
7 => 8
8 => 9
9 => 10
stderr
PHP Notice:  Undefined offset: 1 in /home/s3ol8Q/prog.php on line 21
PHP Notice:  Undefined offset: 0 in /home/s3ol8Q/prog.php on line 21