How to import all the defined variables in one scope to another scope. {Code...} // How to import all the defined variables in one of the scopes to another.
Function test () {$ name = 'programmer '; $ sex = 'male'; $ holobby = 'play computer game';} function test1 () {$ var_list = get_var_list ('test'); // How can this function be defined to obtain all the defined variables in the test function? Extract ($ var_list); // import it to the current function scope. Echo $ name;} test1 ();
Reply content:
// How to import all the defined variables in one scope into another scope.
Function test () {$ name = 'programmer '; $ sex = 'male'; $ holobby = 'play computer game';} function test1 () {$ var_list = get_var_list ('test'); // How can this function be defined to obtain all the defined variables in the test function? Extract ($ var_list); // import it to the current function scope. Echo $ name;} test1 ();
Php> = 5.3.0
Put test1 () into test (). Anonymous Function
Function test () {// load the data into an array $ res = array ($ name = 'programmer '; $ sex = 'male '; $ holobby = 'play computer game';); // return data return $ res;} function test1 () {// call the text method to obtain data, use $ data to receive $ data = test ();//.......}