Anonymous functions In PHP

furious

New member
Registered
Joined
Nov 10, 2013
Messages
11
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.
 
Older Threads
Replies
0
Views
3,146
Replies
2
Views
3,320
Replies
8
Views
5,083
Replies
2
Views
15,076
Newer Threads
Replies
13
Views
9,373
Replies
4
Views
3,341
Replies
4
Views
4,484
Replies
6
Views
3,337
Replies
16
Views
17,604
Latest Threads
Replies
2
Views
35
Replies
2
Views
37
Replies
0
Views
24
Replies
0
Views
31
Replies
0
Views
187
Recommended Threads
Replies
5
Views
1,965
Replies
6
Views
3,708
Replies
10
Views
3,414

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

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