What is Anonymous function or Closure in Php?

These are the function with no defined function. Mostly used for callback.

These are accessed by the variables on which they are defined or invoked dynamically.

$yourVariable = function(){return 1+1};
//now the variable has 2 as value

$areaOfCircle = function($a){ return 3.14*$a*$a;};
$yourOtherVariable = $areaOfCircle(7);
//now the variable has 153.86 as value 

Leave a Reply

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