In the following example, is it possible to access the ‘str’ value from within the anonymous function?
$foo = array(
'str' => 'THIS IS A STRING',
'fn' => function () {
// is it possible from within here to access 'str'?
}
);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if
$foois defined in the global namespace you should be able to access it via$GLOBALS['foo']['str'](or make it available via theglobal $foo;construct). If it isn’t (local var, parameter, member variable, …), you have to pass it (as reference!) to the anonymous function: