public function test()
{
$x = 10;
$collection = collect([0, 10, 20]);
$collection = $collection->map(function ($item, $key){
return $item + $x;
});
}
I want to access the $x
variable within the map
function: how to do it?
When I try to get the value I got this error message:
ErrorException: Undefined variable: x