0

The first one with equals will work and I would expect that. But the second is not working as expected.

    $nicktest = "new"; 
 if ($nicktest == "new" || $nicktest == "fun" || $nicktest == "norm" || $nicktest == "pvp")
        {
            $odpoved = "Ok it works.";
            echo $odpoved;
            return;
}

        $nicktest = "new"; 
 if ($nicktest != "new" || $nicktest != "fun" || $nicktest != "norm" || $nicktest != "pvp")
        {
            $odpoved = "Ok it works too why?";
            echo $odpoved;
            return;
}
  • 1
    Your second if will always be true. Think about it: How can something be equal to `new` and `fun` at the same time?! – Rizier123 Mar 30 '16 at 22:26
  • To check if something is equal to one in a list of items, use `or`/`||`, to check if it is NOT something, use `and`/`&&`. – Jon Mar 30 '16 at 22:30

1 Answers1

0

Your 4 conditions get the following evaluation:

false, true, true, true

Now,

if (false || true || true || true) {
    // Code block is actually evaluated
}

If you would happen to have:

if (false || false || false || false) {
    // Code block wouldn't be evaluated
}

Under this scheme, at least one true condition would get the code to be evaluated

Eduardo Escobar
  • 3,301
  • 2
  • 18
  • 15