Home >Backend Development >PHP Tutorial >I am the Fire Phoenix of Special Forces Episode Episode Introduction to PHP Function Syntax 1

I am the Fire Phoenix of Special Forces Episode Episode Introduction to PHP Function Syntax 1

WBOY
WBOYOriginal
2016-07-29 08:40:051700browse

Copy code The code is as follows:


function getAdder($x)
{
return function ($y) use ($x) {
return $x + $y;
};
}
$adder = getAdder(8);
echo $adder(2); // prints "10"


Here, getAdder() function creates a closure using parameter $× (keyword "use" forces getting variable context) , which takes additional arguments $Y and returns to the call. This function can be stored as a parameter to another function, etc. See the Lambda Functions and Closure RFC for details.

The above has introduced the introduction to the PHP function syntax of I Am the Special Forces Fire Phoenix Episode One, including the introduction to the plot episodes of I Am the Fire Phoenix Special Forces. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn