"php variables in anonymous functions" Code Answer

3

Yes, use a closure:

functionName($someArgument, function() use(&$variable) {
  $variable = "something";
});

Note that in order for you to be able to modify $variable and retrieve the modified value outside of the scope of the anonymous function, it must be referenced in the closure using &.

By Shurmajee on November 17 2022

Answers related to “php variables in anonymous functions”

Only authorized users can answer the search term. Please sign in first, or register a free account.