如题所述
第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();本回答被提问者采纳
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();本回答被提问者采纳