gpt4 book ai didi

php - 切换语句以设置事件菜单项

转载 作者:行者123 更新时间:2023-11-28 14:42:57 26 4
gpt4 key购买 nike

好吧,所以我想我可以这样做,但也许不能。这可能吗?

$url = $_SERVER['REQUEST_URI'];

$active = 'class="bob"';

switch($url){

case('/index.php'):
$active[0] = ' class="active"';
break;

case('/about.php'):
case('/our-customers.php'):
case('/our-partners.php'):
case('/our-clients.php'):
case('/our-standards.php'):
case('/our-awards.php'):
$active[1] = ' class="active"';
break;

case('/solutions.php'):
$active[2] = ' class="active"';
break;

case('/services.php'):
$active[3] = ' class="active"';
break;

case('/sustainability.php'):
case('/what-are-we-doing.php'):
case('/what-can-you-do.php'):
case('/what-we-support.php'):
case('/references.php'):
$active[4] = ' class="active"';
break;

case('/healthcare.php'):
$active[5] = ' class="active"';
break;

case('/blog/'):
$active[6] = ' class="active"';
break;

case('/contact.php'):
$active[7] = ' class="active"';
break;
}

?>

?>

<nav>
<ul class="clearfix">
<li <?php echo $active[0] ?> id="first"><a href="index.php" class="Bold">Home</a></li>
<li <?php echo $active[1] ?>><a href="about.php" class="Bold">About</a></li>
<li <?php echo $active[2] ?>><a href="solutions.php" class="Bold">Solutions</a></li>
<li <?php echo $active[3] ?>><a href="services.php" class="Bold">Services</a></li>
<li <?php echo $active[4] ?>><a href="sustainability.php" class="Bold">Sustainability</a></li>
<li <?php echo $active[5] ?>><a href="healthcare.php" class="Bold">Healthcare</a></li>
<li <?php echo $active[6] ?>><a href="/blog/" class="Bold">Blog</a></li>
<li <?php echo $active[7] ?> id="last"><a href="contact.php" class="Bold">Contact</a></li>
</ul>
</nav>

最佳答案

替换行

$active = 'class="bob"'

通过

$active = array("","","","","","","");

关于php - 切换语句以设置事件菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5661886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com