How do you import all the defined variables in one of the scopes into another scope.
function test(){ $name = 'programmer'; $sex = 'male'; $hobby = 'play computer game';}function test1(){ $var_list = get_var_list('test'); // 这个函数该怎样定义才能够获取 test 函数中所有已定义的变量? extract($var_list); // 将其导入到当前函数作用域中。 echo $name;}test1();
Reply content:
How do you import all the defined variables in one of the scopes into another scope.
function test(){ $name = 'programmer'; $sex = 'male'; $hobby = 'play computer game';}function test1(){ $var_list = get_var_list('test'); // 这个函数该怎样定义才能够获取 test 函数中所有已定义的变量? extract($var_list); // 将其导入到当前函数作用域中。 echo $name;}test1();
PHP >= 5.3.0
Put test1 () into Test (). Anonymous Function
function test(){ // 把数据装入一个数组 $res = array( $name = 'programmer'; $sex = 'male'; $hobby = 'play computer game'; ); // 返回数据 return $res;}function test1() { // 调用 text方法 拿到数据, 用 $data 来接收 $data = test(); // .......}