Question:

How do I say IF Something equals Something OR Something else Equals Something else

by  |  earlier

0 LIKES UnLike

Hi there,

I need to find out to how say:

if (var1 == "a" OR var2 == "a")

The above is just an example of what I need

Thanks!

 Tags:

   Report

2 ANSWERS


  1. if (var1 == "a" || var2 == "b")

    {

    }

    Use the double pipe ( || ) for OR and double ampersand ( && ) for AND.


  2. if(($var1 == "a") || ($var2 == "b"))

    {

    // Do something

    }

    That's in PHP.

    || = OR

    && = AND

    (at least in PHP)

    How it returns true:

    $var1 = a

    OR

    $var2 = b

    How it returns false:

    $var1 = x

    $var2 = y

    Since neither one equals what you defined then it will not return true.  It's checking to see if either variable equals what you defined.

    Thanks,

    Chad

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.