IF in PHP does not work

Asked

Viewed 312 times

-2

If I’m on the test page/1, it adds the class logoPrincipalHosp in li if not the class logoPrincipalElev.

My PHP:

<li <?php if (preg_match('/teste\/1/')) echo 'class="logoPrincipalHosp"';
else (preg_match('/teste\/2/')) echo 'class="logoPrincipalElev"';
?>>

But it’s not working

  • 4

    Shouldn’t be elseif instead of else?

  • 5

    You’re missing a parameter in preg_match =). preg_match

  • 1

    @Sergio was this guy, that lack of attention my, thanks! : D

  • @Oeslei actually I just forgot to put the parameter here, in my code it is already. :)

1 answer

4


If you want to add another condition to be checked on else, then you have to use elseif.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.