W3docs

'AND' vs '&&' as operator

In PHP, both 'AND' and '&&' are logical operators that are used to test if two statements are true.

In PHP, both AND and && are logical operators used to test if two statements are true. However, they do not have the same precedence: && has a higher precedence than AND.

The main difference is their precedence level. AND has lower precedence than the assignment operator =, while && has higher precedence. Because of this, && is generally preferred in assignments and complex expressions to avoid unexpected behavior.

Here is an example of how you might use these operators:

The difference between 'AND' vs '&&' as operator in PHP

php— editable, runs on the server

In both cases, the output will be "True!" because both statements are true.

Precedence difference in assignments

<?php

$a = true AND false; // $a becomes true
$b = true && false;  // $b becomes false

var_dump($a, $b);

In the first assignment, AND has lower precedence than =, so it evaluates as ($a = true) AND false;. In the second, && has higher precedence, so it evaluates as $b = (true && false);.