Skorpius

Closure/Anonymous Function

Jun 12th, 2022 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.25 KB | None | 0 0
  1. <?php
  2.  
  3.     //To use the var $name in the closure you need to add use ($name) as below
  4.     $name = 'Elvis';
  5.     $greet = function() use ($name){
  6.         echo "Hello there, $name.";
  7.     };//Semi colon must be at end of closure
  8.  
  9.     //To call/Use the closure
  10.     $greet();
  11.  
  12. ?>
Add Comment
Please, Sign In to add comment