Anonymous function

Definition

Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters (…) • php.net

Usage

Typical use is for a lambda or a closure, or anywhere a callback function is required as a parameter of a function.

Examples

// anonymous function
function () {  
	return "Hello world";  
}  

// anonymous function with parameter
function ($name) {  
	return "Hello $name";  
}  

// anonymous function with scope inheritance
function ($name) use ($language) {  
	return $language === 'fr' ? "Bonjour $name" : Hello $name";  
}  

References

Related articles