Created
October 18, 2017 22:19
-
-
Save VictorFursa/7ee67b3bfe9d1045e7664b211b0ae4fd to your computer and use it in GitHub Desktop.
Closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** example */ | |
$text = function (string $text) { | |
return $text; | |
}; | |
$text('hello'); //return hello | |
$text = 'sum = '; | |
//в use можно передать несколько переменных function() use($var1, $var2) { } | |
$sum = function ($a, $b) use ($text) { | |
$sum = $a + $b; | |
return $text . $sum; | |
}; | |
$sum(2, 3); //return sum = 5 | |
$text = 'new text'; | |
$sum(3, 3); //return sum = 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment