当2个PHP页面使用require()调用时,如何在2个PHP页面之间传递变量

问题描述:

我是PHP新手,并且我有以下问题:

I am a PHP newbie, and I have this question:

说我有:

$a = 'foo' ;
$b = 'baz' ;
require ('b.php') ;


如何将变量$ a和$ b传递给b.php? 如何在b.php中使用这些变量?


How do I pass variables $a and $b to b.php ? How do I use these variables in b.php ?

非常感谢!

只要确保在设置变量后调用require(),它们就可以在b.php中使用.

Just make sure you call require() after setting the variables, and they should be available in b.php.

a.php:

$a = 'foo';
$b = 'baz';
require('b.php');

b.php:

echo 'a: '. $a;
echo 'b: '. $b;