I was playing around with anonymous functions in PHP and realized that they don't seem to reach variables outside of them.
Is there any way to get around this problem?
Example:
$variable = "nothing";
functionName($someArgument, function() {
$variable = "something";
});
echo $variable; //output: "nothing"
This will output "nothing". Is there any way that the anonymous function can access the $variable
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…