php if else使用$ thisPage

ken*_*eso -2 html php

我有一个基于我需要更改href和链接文本的页面的导航,但无法让它工作.

这就是我需要的

<?php
if ($thisPage=="Index-EN" || "Index-IT") {
?>
    <li><a href="#" class="scroll-link" data-id="about"><?php echo MENU_ABOUT ?>AAA</a></li>
    <li><a href="#" class="scroll-link" data-id="gallery"><?php echo MENU_GALLERY ?></a></li>
    <li><a href="<?php echo MENU_CONTACTS_LINK_HOME ?>"><?php echo MENU_CONTACTS ?></a></li>
<?php
} else {
?>
    <li><a href="index.php#about" data-id="about"><?php echo MENU_ABOUT ?>BBB</a></li>
    <li><a href="index.php#gallery" data-id="gallery"><?php echo MENU_GALLERY ?></a></li>
    <li><a href="<?php echo MENU_CONTACTS_LINK ?>"><?php echo MENU_CONTACTS ?></a></li>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)

这就是我尝试过的,我知道这是错误的,因为导航消失了

<?php
if ($thisPage=="Index-EN" || "Index-IT") {
echo '
    <li><a href="#" class="scroll-link" data-id="about">' . MENU_ABOUT . 'AAA</a></li>
    <li><a href="#" class="scroll-link" data-id="gallery">' . MENU_GALLERY . '</a></li>
    <li><a href="' . MENU_CONTACTS_LINK_HOME . '">' . MENU_CONTACTS . '</a></li>'
} else {
echo '
    <li><a href="index.php#about" data-id="about">' . MENU_ABOUT . 'BBB</a></li>
    <li><a href="index.php#gallery" data-id="gallery">' . MENU_GALLERY . '</a></li>
    <li><a href="' . MENU_CONTACTS_LINK_HOME . '">' . MENU_CONTACTS . '</a></li>'
}
?>
Run Code Online (Sandbox Code Playgroud)

Som*_*ken 6

if ($thisPage=="Index-EN" || "Index-IT") 
Run Code Online (Sandbox Code Playgroud)

true由于第二个表达式,这将始终进行评估.您应该显式添加另一个==以检查是否相等:

if ($thisPage == "Index-EN" || $thisPage == "Index-IT") 
Run Code Online (Sandbox Code Playgroud)