<img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/image/467/414/724/1617330675913128.jpg" class="lazy" title="1617330675913128.jpg" alt="Tips for using anonymous functions in PHP">
Anonymous functions
(Anonymous functions) in PHP
are also called closure functions
(closures), allows specifying a function without a name. The most commonly used one is the parameter value of callback function
.
1. Reference local variables in anonymous functions (use the use keyword in PHP here).
1 2 3 4 5 6 7 8 9 10 11 12 |
|
2. Place the anonymous function in a normal function, or return the anonymous function.
1 2 3 4 5 6 7 8 9 |
|
3. Return in an ordinary function.
1 2 3 4 5 6 7 8 9 10 |
|
4. Return the anonymous function and pass parameters to the anonymous function.
1 2 3 4 5 6 7 8 9 10 11 |
|
5. Pass anonymous functions as parameters.
1 2 3 4 5 6 7 8 9 10 |
|
Recommended: 《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of Tips for using anonymous functions in PHP. For more information, please follow other related articles on the PHP Chinese website!