I am studying callbacks
and I came across a method that I can not recover and I find it even simpler to send the variables into the function that is the use operator, but I do not know how to get it inside this function my_function ().
So far I have understood, the first is callback
of function
and second is the parameter of my_function ().
function my_function($call, array $foo) {
return $foo['ra'];
}
$bar = ['ra' => '853-5'];
$str = my_function(function($data) {
return $data;
}, $bar);
var_dump($str); //string(5) "853-5"
But for me to use it this way!
$str = my_function(function($data) use ($bar) {
return $data;
});
And not having to pass the second parameter to the function, but by the operand and use
. How do I get this data passed by the use
operator in my_function ()?
Thanks in advance for the answer!