所以我想知道当在多个php文件中使用变量名时,是否可以从特定的php文件中获取变量. 一个例子是这样的:
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:
<header> <title> <?php echo $var1; ?> </title> </header>page1.php具有$var1 = 'page1' page2.php具有$var1 = 'page2'
page1.php has $var1 = 'page1' page2.php has $var1 = 'page2'
footer.php应该具有<a href="">$var1 from page1</a><a href="">$var1 from page2</a>
footer.php should have <a href="">$var1 from page1</a><a href="">$var1 from page2</a>
好吧,这个例子有点抽象,但是就我所能讲的那么短.我想你明白我的意思了!所以这就是我追求的页脚!有任何解决方案吗?
Ok the example is a bit abstract, but as short as I can make it. I think you get what I am getting at! So it is the in the footer I am after! Got any solutions?
推荐答案可以,但是最后一个include中的变量将覆盖第一个中的变量:
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;输出:
测试
测试器
我建议使用不同的变量名.
I suggest using different variable names.
更多推荐
PHP,从另一个php文件获取变量
发布评论