mercury
mercury

Reputation: 2765

php anonymous function parameters

I'm trying to understand Anonymous Functions in php (laravel framework) , I searched about my basic question here but I didn't find the answer.

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

What parameters gone inside the anonymous function ??

Route::match(['get', 'post'], '/', function () {
    return 'Hello World';
});

Upvotes: 0

Views: 59

Answers (1)

Jessica
Jessica

Reputation: 7005

http://php.net/preg_replace_callback

A callback that will be called and passed an array of matched elements in the subject string. The callback should return the replacement string. This is the callback signature:

So it sends in the array of matches.

Upvotes: 1

Related Questions