diff options
author | Malcolm Fell <malcolm@vendhq.com> | 2013-06-28 09:11:27 +1200 |
---|---|---|
committer | Malcolm Fell <malcolm@vendhq.com> | 2013-06-28 09:11:27 +1200 |
commit | be46dc081a255d85a1b1331b4fcd949196699b7c (patch) | |
tree | cf7f69dc2de0f3257af52faf031a23654da17f42 | |
parent | 91957c7cc2b1b0ecf131071ca7c7a2808d241f34 (diff) |
Add example of currying
-rw-r--r-- | php.html.markdown | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/php.html.markdown b/php.html.markdown index 8f319930..ae636b0a 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -300,6 +300,23 @@ function outer_function ($arg_1 = null) { // $arg_1 is optional // inner_function() does not exist and cannot be called until outer_function() is called ``` +This enables [currying](http://en.wikipedia.org/wiki/Currying) in PHP. + +```php +function foo ($x, $y, $z) { + echo "$x - $y - $z"; +} + +function bar ($x, $y) { + return function ($z) use ($x, $y) { + foo($x, $y, $z); + }; +} + +$bar = bar('A', 'B'); +$bar('C'); +``` + ### [Variable](http://www.php.net/manual/en/functions.variable-functions.php) ```php |