Created
December 11, 2013 09:59
-
-
Save ritalin/7907842 to your computer and use it in GitHub Desktop.
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
// こんなふうに、外側の変数を束縛すると、関数定義を変更する必要が無くなる | |
function outer() { | |
$n = 10; | |
$m = 200; | |
my_func(function($i, $x) use($n) { return $n + $n }, [10, 20, 30]); | |
my_func(function($i, $x) use($n, $m) { return $n + $n * $m }, [10, 20, 30]); | |
} | |
function mt_func(closure $callback, array $a) { | |
foreach ($a as $x) { | |
echo $callback($x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment