PHP 5.3 Introduction to Anonymous Functions

Standard

New to PHP 5.3 is the introduction of anonymous function. Anonymous functions also known as closures are methods that do not require a specified name to be assign to a function.

Prior to 5.3

Now using anonymous function

As you can see we are accomplishing the same tasks, however the anonymous function method do become useful if you wish to write them for definitions of other methods.

Take for example that we want to filter out all values that do not equal 3 or 4.

The result is as expected.