PHP包括,下拉式导航选定问题
我有一个用于导航的PHP include。我想确保显示当前菜单链接,这样我就有了一个类PHP包括,下拉式导航选定问题,php,include,Php,Include,我有一个用于导航的PHP include。我想确保显示当前菜单链接,这样我就有了一个类当前菜单项。除下拉链接外,所有功能都正常 每页都有一个 如果不正确,我有你对的用法。如果$current\u page=='dev'或seo,则其计算结果为true,且非空字符串的计算结果始终为true 应该是: <?php if ($current_page == 'dev' || $current_page == 'seo' || $current_page == 'mobile' || $curre
当前菜单项
。除下拉链接外,所有功能都正常
每页都有一个
如果不正确,我有
你对的用法。如果$current\u page=='dev'
或seo
,则其计算结果为true,且非空字符串的计算结果始终为true
应该是:
<?php if ($current_page == 'dev' || $current_page == 'seo' || $current_page == 'mobile' || $current_page == 'social' || $current_page == 'hosting') echo "current-menu-item"; ?>
或者更简单:
<?php if (in_array($current_page, array('dev', 'seo', 'mobile', 'social', 'hosting')) echo "current-menu-item"; ?>
此if语句:
if($current_page == 'development' || 'seo' || 'mobile' || 'social' || 'hosting')
不一定是无效的,但你用错了。|
表示OR,因此它实际上会分割您的条件这是您当前状况的处理方式:
if(
$current_page == 'development' ||
'seo' == true; ||
'mobile' == true; ||
'social' == true; ||
'hosting' == true;
)
因此,当然,由于seo、移动、社交和主机不等于虚假,所以它总是真实的
执行您尝试执行的操作的最佳方法是使用可接受的值创建一个数组,然后使用如下方法检查该值:
$pages = Array("development","seo","mobile","social","hosting");
if(in_array($current_page,$pages);
$pages = Array("development","seo","mobile","social","hosting");
if(in_array($current_page,$pages);