PHP: Anonymous functions

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, but they have many other uses. as example:

echo preg_replace_callback('~-([a-z])~', function ($match) {
// outputs helloWorld


another one:

= function($name)
printf(“Hello %s\r\n”$name);


this concept is available from PHP 5.3

PHP: Anonymous functions – Manual.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s