function ($parameter) use ($data) { ... }
to capture stuff from the local environment.Edit: And you can pass by reference:
> $stuff = [1]
= [
1,
]
> $fn = function ($par) use (&$stuff) { $stuff[] = $par; }
= Closure($par) {#3980 …2}
> $fn(2)
= null
> $stuff
= [
1,
2,
]
Never done it in practice, though, not sure if there are any footguns besides the obvious hazards in remote mutation.