当2个PHP页面使用require()调用时,如何在2个PHP页面之间传递变量 [英] how to pass variables between 2 php pages when the latter called with require()
本文介绍了当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;
这篇关于当2个PHP页面使用require()调用时,如何在2个PHP页面之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文