How does PHP get all the defined variables within a function??

Source: Internet
Author: User
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();        // .......}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.