Guest User

Untitled

a guest
Feb 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. <?php
  2. function create_closure( $count ) {
  3. return function() use ( &$count ) {
  4. return $count--;
  5. };
  6. }
  7. $closure = create_closure( 10 );
  8. $another_closure = create_closure( 20 );
  9.  
  10. echo $closure(); // 10
  11. echo $another_closure(); // 20
  12. echo $closure(); // 9
  13. echo $closure(); // 8
  14. echo $another_closure(); // 19
Add Comment
Please, Sign In to add comment