PHP custom function anonymous function

The so-called anonymity means having no name.

Anonymous function is a function without a function name.

The first usage of anonymous functions is to directly assign the assignment value to the variable, and calling the variable is to call the function.

The writing method of anonymous functions is more flexible.

1. Variable functional anonymous function

The function body in the above example has no function name and is called through $greent plus parentheses. This is anonymous function.

2. Callback-style anonymous function

Let’s take the previous example. In actual usage scenarios, we need to implement more functions through a function. However, I don't want to specifically define a function. Let’s review the example of our callback function:

Let’s reason about the process carefully. It’s just that in the previous chapter, plusx2 was replaced by our anonymous function:

Therefore, the function name function does not have a function name when it is called. We can use anonymous functions in some of the above ways.


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!