Home  >  Article  >  Backend Development  >  anonymous function

anonymous function

angryTom
angryTomforward
2019-10-22 17:55:452925browse

anonymous function

Anonymous functions, also called closures, allow you to temporarily create a function without a specified name. The value most commonly used as a callback function argument. Of course, there are other applications as well.

Implementation structure

anonymous function

anonymous function

anonymous function

## Closure: Put the anonymous function in a normal function, or you can return the anonymous function, which forms a simple closure

Keywords: use connects the variables and values ​​of the context

Application scenarios of closures:

①, to protect the safety of variables within the function. The variables in the outer function can only be accessed by the inner function, and cannot be accessed through other means

②. The variables in the outer function always exist in the memory, so they will be used every time it is executed.

The above is the detailed content of anonymous function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.catchit.top. If there is any infringement, please contact admin@php.cn delete