How to pass a variable to a function with callback?

Posted 2 months ago by MartinZeltin

I could not find anywhere how to pass a variable to my function that uses a callback.

This is giving me an error

NOTICE Undefined variable: data on line number 2
function doIt($callback) { 
    $callback($data); 
}


doIt(function($data) {
    echo 'Anonymous function: ' . $data;
}); 

Please sign in or create an account to participate in this conversation.