Skip to end of metadata
Go to start of metadata

PHP provides super easy feature can put a function as a part of function parameter. You can just put it like function exampleMethod( $customFunc).

In order to do it, the function must be coded like a variable as below:

$myFunc = function( $param1, $param2)
{
	your logic...

};

Note that the function variable must be declared like a normal variable, and its functional code must be ended by semicolon.


Below is an example

<?

function test( $customFunc, $a, $b)
{
    return $customFunc( $a, $b);
}

$custMul = function($a, $b)
{
        return ($a*$b);
};

$custDiv = function($a, $b)
{
        return ($a/$b);
};

echo test( $custMul, 4, 2) . "\n";
echo test( $custDiv, 4, 2) . "\n";

?>