Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. foreach (range(1,10) as $value) {
  2. // do something
  3. }
  4.  
  5. function foo() {
  6. global $counter;
  7. $counter++;
  8. return range(1, 10);
  9. }
  10.  
  11. $counter = 0;
  12. foreach (foo() as $key => $value) {}
  13. printf("The function was executed %d time(s)n", $counter);
  14.  
  15. $counter = 0;
  16. $result = foo();
  17. foreach ($result as $key => $value) {}
  18. printf("The function was executed %d time(s)n", $counter);
  19.  
  20. function getrange()
  21. {
  22. error_log("running getrange()");
  23. return range(1,10);
  24. }
  25.  
  26. foreach(getrange() as $val)
  27. {
  28. ...
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement