Advertisement
kromm77

php yield example

Oct 26th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.33 KB | None | 0 0
  1. <?php
  2.  
  3. function yield_test() {
  4. $timestart=time();
  5. print "first element retrieved... ";
  6. yield (time()-$timestart);
  7. print "second element retrieved... ";
  8. yield (time()-$timestart);
  9. print "third element retrieved... ";
  10. yield (time()-$timestart);
  11. }
  12.  
  13.  
  14. foreach (yield_test() as $v ) {
  15. print $v." seconds passed\n";
  16. sleep(2);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement