Skip to content

Instantly share code, notes, and snippets.

@nurullahisik
Created March 12, 2019 06:14
Show Gist options
  • Save nurullahisik/faa249dffaee013719a51472573a92a7 to your computer and use it in GitHub Desktop.
Save nurullahisik/faa249dffaee013719a51472573a92a7 to your computer and use it in GitHub Desktop.
<?php
$var1 = 10;
$var2 = 3;
$closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) {
echo $var1;
};
$closureWithArgsAndVars(8, 9);
echo "<br><br>";
$param = 'John!';
function sayHello()
{
$param = 'Michael!';
$func = function() use ($param)
{
$param = 'Dave!';
};
$func();
echo 'I am ' . $param; // prints I am Michael!
}
sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment