Difference between the AND and && operator in php



'AND' Logical operator

'AND' operator is a logical AND operator but has low precedence to = operator.

'&&' Logical operator

'&&' is also a logical AND operator but has high precedence to = operator.

Example

Following the example, shows the difference of 'AND' vs '&&' operators.

 Live Demo

<!DOCTYPE html> <html> <head>    <title>PHP Example</title> </head> <body>    <?php       $x = true;       $y = false;       $result = $x AND $y;       print('$result = $x AND $y');       print("<br/>");       var_dump($result);       print("<br/>");       $result = $x && $y;       print('$result = $x && $y');       print("<br/>");       var_dump($result);    ?> </body> </html>

Output

$result = $x AND $y bool(true) $result = $x && $y bool(false)
Updated on: 2020-01-13T06:39:02+05:30

438 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements