Quote:
Originally Posted by Mickie D
So the AND does not look at the code as
usergroup 6 and usergroup 7
it looks at it like
usergroup 6 and 7
because the 6 is on the left of the AND, would that also be true with OR
|
Well, yes, I think. The expression ($x != 6 AND 7) has 3 values separated by 2 operators, so in what order would you evaluate it? It turns out that != has higher precedence than AND (as you can see in this
table of operator precedence), so that means the 6 goes with the !=, and the result of that is ANDed with 7.
But I should also point out (just to make it more confusing) that even if AND were higher so that the expression 6 AND 7 were evaluated first, it still doesn't do what you'd want, so in a way I guess this is an overly complicated answer to your question. I suppose it's just that sometimes if you read the code like it's English it means something different than it does in php, so $x != 6 AND 7 might make sense in English, but it's not correct php (or at least it's not correct for what you're trying to do).
Live Dave says, it's usually easier to use in_array(), although I feel that if you only have 2 values then ANDing 2 checks is not so bad. But I'm not an expert php programmer, escpecially when it comes to style.
Oh, and yeah, OR would be the same.