php 怎么获取一个函数内所有已定义的变量

如题所述

第1个回答  2017-11-01
php >= 5.3.0
Put test1() into test(). Anonymous Function

<?phpfunction test(){
$name = 'programmer';
$sex = 'male';
$hobby = 'play computer game';
//combine all variables into an associative array.
$vars_keys = ['name', 'sex', 'hobby'];
$vars = compact($vars_keys);
//inject the variables array into test1().
$test1 = function () use ($vars) { //extract the array to numerous variables.
extract($vars); echo $name;
};
//you have to call it here.
$test1();
}

test();本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网