如何确保页面是index.php和!用于导航高亮显示的isset($\u GET)

如何确保页面是index.php和!用于导航高亮显示的isset($\u GET),php,nav,Php,Nav,当链接指向页面时,我会突出显示导航链接。然而,由于我的一些链接只是带有GET变量的index.php,我很难用index.php区分它们 例如,index.php和index.php?get=**和$\u服务器['php\u SELF']都是/index.php。如何确保页面位于index.php,而没有任何get变量 这是我的导航高亮代码 <?php if( $_SERVER['PHP_SELF'] == '/index.php' && ! isset($

当链接指向页面时,我会突出显示导航链接。然而,由于我的一些链接只是带有GET变量的index.php,我很难用index.php区分它们

例如,
index.php
index.php?get=**
$\u服务器['php\u SELF']
都是
/index.php
。如何确保页面位于index.php,而没有任何get变量

这是我的导航高亮代码

<?php
if( $_SERVER['PHP_SELF'] == '/index.php'
    &&
    ! isset($_GET)
)
{ echo 'class="white"'; }

您可以检查$\u GET是否为空,如下所示:

if(empty($_GET)) {
    // there are no GET paramas set this is index.php
} else {
    // there are GET params set
}

因为
$\u GET
是一个(超全局)数组,所以可以检查是否设置了元素

if(count($_GET) == 0) {
  // index.php
} else {
  // get params ...
}

正确地说,
$\u GET
总是设置的。是的,$\u GET总是在Web服务器上下文中设置的。您需要检查它是否为空,如下面的答案所示。