例如,当您将网站切换为Jedi或Sith主题时,您还将在Jedi和Sith主题中包含相同的$color2
,而不需要在两个主题中使用相同的变量。
类似:
if (isset($_GET['jedi']))
{
$color = "#299CF5";
$color2 = "#F456C2";
}
elseif (isset($_GET['sith']))
{
$color = "#f45341";
$color2 = "#F456C2";
}
应该是这样的:
if (isset($_GET['jedi']))
{
$color = "#299CF5";
}
elseif (isset($_GET['sith']))
{
$color = "#f45341";
}
elseif (isset($_GET['jedi']) || isset($_GET['sith']))
{
$color2 = "#F456C2";
}
在HTML中:
<h3>Change your favourite theme of<span style="color: <?php echo $color ?>">Star Wars</span> of <span style="color: <?php echo $color2 ?>"> Gustavo</span></h3> <br>
<a href="index.php&jedi">Jedi</a> <br>
<a href="index.php&sith">Sith</a> <br>
<?php echo $color; ?> <br>
<?php echo $color2; ?>
西斯主题的输出:
<h3>Change your favourite theme of <span style="color: #f45341">Star Wars</span> of <span style="color: #F456C2"> Gustavo</span></h3>
<a href="index.php&jedi">Jedi</a> <br>
<a href="index.php&sith">Sith</a> <br>
<br>
#f45341 <br>
#F456C2
&#13;
Jedi主题中的输出:
<h3>Change your favourite theme of <span style="color: #299CF5">Star Wars</span> of <span style="color: #F456C2"> Gustavo</span></h3>
<a href="index.php&jedi">Jedi</a> <br>
<a href="index.php&sith">Sith</a> <br>
<br>
#299CF5 <br>
#F456C2
&#13;
我也尝试过:
elseif (!isset($_GET['jedi']) || isset($_GET['sith']))
{
$color2 = "#F456C2";
}
elseif (!isset($_GET['jedi'], $_GET['sith']))
{
$color2 = "#F456C2";
}
elseif (isset($_GET['jedi'], $_GET['sith']))
{
$color2 = "#F456C2";
}
所有这些方式都没有检测到$color2
。
答案 0 :(得分:0)
您真正需要做的就是更改第二个代码
if (isset($_GET['jedi']))
{
$color = "#299CF5";
}
elseif (isset($_GET['sith']))
{
$color = "#f45341";
}
elseif (isset($_GET['jedi']) || isset($_GET['sith']))
{
$color2 = "#F456C2";
}
到
if (isset($_GET['jedi']))
{
$color = "#299CF5";
}
elseif (isset($_GET['sith']))
{
$color = "#f45341";
}
if (isset($_GET['jedi']) || isset($_GET['sith']))
{
$color2 = "#F456C2";
}