Anonymous functions (closures) can be stored in variables or passed as callbacks. To access an outer variable inside a closure, import it with use ($var). For short one-line callbacks, PHP 7.4+ arrow functions (fn($x) => ...) capture outer variables automatically.
ADVERTISEMENT