After allot of coding of late, thought that I would place online a great syntax called lambda which allows you to do assign functions to a variable that is callable!!. So the functions like pref_replace_callback that has a function as the parameter to be used if any matches are meet.

So for a example, I think that source code always works the best.

function newFun ($name) { 
	$call = function ($second) use ($name) {
		return $second . $name; 
	return $call($name);
echo newFun("hi there");

and the output would be

hi therehi there

What it is doing is assigning to the $call variable is the actual function call! which is able to be able to pass in via the parameters a parameter but also to “use” local variables within the function. The $name is passed in to the newFun function and is then use[d] within the lambda function, how cool is that!.

Leave a Reply

Your email address will not be published. Required fields are marked *