mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Add example of currying
This commit is contained in:
parent
91957c7cc2
commit
be46dc081a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user