关于php include 文件后,根据需求修改变量的问题
本文介绍了关于php include 文件后,根据需求修改变量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
有这些文件
nav.php (公共部分)
a.php
b.php
c.php
d.php
e.php
nav.php 中代码
<?php
$tf = "false";
echo
'<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf . ' }"></dt></dl>'
?>
a.php,b.php,c.php,d.php,e.php 都引入nav.php
<?php include '../nav.php'; ?>
现在我希望打开 a.php 的时候,上面第一个 <dt></dt> 中的 $tf = "true"; 其他为$tf = "false";
同理,打开b.php的时候,第二个 <dt></dt> 中的 $tf = "true"; 其他为$tf = "false";
求解,谢谢!
解决方案
nav.php
<?php
unset($tf);
global $tf;
$tf = array_pad(array(), 5, 'false');
function common($tf) {
echo
'<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf[0] . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf[1] . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf[2] . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf[3] . ' }"></dt></dl>
<dl><dt class="qp-ui" data-qp-ui="{ \'SideNavZippy\':' . $tf[4] . ' }"></dt></dl>';
}
?>
a.php
include '../nav.php';
global $tf;
$tf[0] = 'true';
common($tf);
b.php
include '../nav.php';
global $tf;
$tf[1] = 'true';
common($tf);
这篇关于关于php include 文件后,根据需求修改变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文