1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php $caller = function (string $a, callable $b): int { return $b($a); }; $p = function (string $a): void { echo $a . PHP_EOL; }; $total = 100; $add = function (int $point) use (&$total): int { $total += $point; return $total; }; $p('total : ' . $total); $p($caller(123, function ($arg) use ($add): int { return $add($arg); })); $p('total : ' . $total); |
1 2 3 |
total : 100 223 total : 223 |