PHP, getting variable from another php-file

前端 未结 4 607
遥遥无期
遥遥无期 2020-11-27 04:18

So I wonder if it is possible to get a variable from a specific php-file when the variable-name is used in multiple php-file. An example is this:



        
4条回答
  •  天命终不由人
    2020-11-27 04:53

    You can, but the variable in your last include will overwrite the variable in your first one:

    myfile.php

    $var = 'test';
    

    mysecondfile.php

    $var = 'tester';
    

    test.php

    include 'myfile.php';
    echo $var;
    
    include 'mysecondfile.php';
    echo $var;
    

    Output:

    test

    tester

    I suggest using different variable names.

提交回复
热议问题