2
votes

I have the following code and don't think and is needed, i.e. && should be used, as there is nothing to assign the left part to?

if($_REQUEST['foo'] != 'abc' and $_REQUEST['bar'] == 'def')
{
    echo "all your base";
}

So it should be:

if($_REQUEST['foo'] != 'abc' && $_REQUEST['bar'] == 'def')
{
    echo "all your base";
}
3

3 Answers

6
votes

In your case, && and and do the same thing, but take a look at the operator precedence. You can see that && and and are not on the same level, so mixing that could give you unexpected results in some cases - I recommend always using &&, but that's your choice.

4
votes

&& and "and" are two different things, because of their precedence.

The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See Operator Precedence.)

2
votes

'and' and '&&' is the same operator, apart from precedence differences.

They are different operators, but they operate the same, apart from precedence differences.