Anonymous functions In PHP

furious

New member
Joined
Nov 10, 2013
Messages
16
Points
0
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.

Example #1 Anonymous function example

<?php
echo preg_replace_callback('~-([a-z])~', function ($match) {
return strtoupper($match[1]);
}, 'hello-world');
// outputs helloWorld
?>

Note: It is possible to use func_num_args(), func_get_arg(), and func_get_args() from within a closure.

The Closure class (PHP 5 >= 5.3.0) used to represent anonymous functions.
 
Newer threads
Replies
12
Views
9,354
Replies
4
Views
3,397
Replies
1
Views
3,932
Latest threads
Replies
0
Views
103
Replies
1
Views
108
Replies
0
Views
94
Replies
2
Views
936
Replies
0
Views
575
Recommended threads
Replies
4
Views
3,115
Replies
5
Views
3,321
Replies
11
Views
6,156
Replies
12
Views
5,344
Replies
2
Views
1,156

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top