或者用PHP语句

I want to add an ID to a span element if the page is either 'a' or 'b'.

My code so far is this:

<span class="subnav2" <? if(($page == 'a') || ($page == 'b')): ?> id="active"<? endif ?>>

but it only adds the class to the span when 'a' is true. What am I doing wrong?

The value of $page is:

<? 
    $path = basename($_SERVER['PHP_SELF']);
    $page = basename($path);
    $page = basename($path, '.php');
    $page = str_replace('_',' ',$page);
    $page = str_replace('.php','',$page);
    $page = ucfirst($page);
?>

try this :
code:

<span class="subnav2" <? if(($page == 'a') || ($page == 'b')): echo "id=\"active\"" endif ?>>

As you may notice, the code works even when $page = 'b'. The problem hides somewhere else, where $page is assigned. In either case, your code will look better this way:

<span class="subnav2" <?= $page == 'a' || $page == 'b' ? 'id="active"' : '' ?>>

Try:

<?php if ($page == 'a' || $page == 'b'): ?>