Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created October 18, 2017 22:19
Show Gist options
  • Save VictorFursa/7ee67b3bfe9d1045e7664b211b0ae4fd to your computer and use it in GitHub Desktop.
Save VictorFursa/7ee67b3bfe9d1045e7664b211b0ae4fd to your computer and use it in GitHub Desktop.
Closure
<?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