Jump to content

Recommended Posts

Not quite like that, but yes you can use it with the correct syntax.

 

<?php

if($tag=='home' || $tag=='about' || $tag=='contact') {

    // DO SOMETHING

} else {

    // DO SOMETHING ELSE

}

?>

 

No, for at least two reasons.

 

First, you have double-quotes around "home || about || contact". That is checking if $tag is equal to the string 'home || about || contact'

 

Secondly, without the quotes, you would be or'ing home with about and then or'ing that with contact and that as a logic expression is equal to TRUE. So you would be checking if $tag is a TRUE value and that would be true for a lot of different values.

 

Computers don't apply the distributive property to what you write. You must explicitly write out the logic test that you want or find a different method.

 

Since you are testing if something is any one of a list of values, it would be easier to put those values into an array and use the in_array function.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.