- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
‘AND’ vs ‘&&’ operators in PHP
The difference is the precedence when we compare AND with && operator. The precedence of AND operator is lower than the operator = when the evaluation is performed, therefore even if both the operators do the same work, the result is different.
Example
Let us first see an example of the AND operator−
<?php $val1 = 55; $val2 = 65; if ($val1 == 55 and $val2 == 65) echo "Result = True"; else echo "Result = False"; ?>
Output
This will produce the following output−
Result = True
Example
Let us now see an example of the && operator−
<?php $val1 = 110; $val2 = 110; if ($val1 == 110 && $val2 == 110) echo "Result = True"; else echo "Result = False"; ?>
Output
This will produce the following output:
Result = True
Example
Let us now see the difference in a single example −
<?php $bool = TRUE and FALSE; echo ($bool ? 'true' : 'false'), "
"; $bool = TRUE && FALSE; echo ($bool ? 'true' : 'false'); ?>
Output
This will produce the following output−
true false
- Related Articles
- ‘AND’ vs ‘&&’ operators in PHP
- IS vs AS Operators in C#
- Inplace vs Standard Operators in Python
- PHP Array Operators
- PHP String Operators
- PHP Type Operators
- PHP Increment/Decrement Operators
- PHP readfile vs. file_get_contents
- Compare define() vs const in PHP
- PHP Generators vs Iterator objects
- Performance of FOR vs FOREACH in PHP
- PHP $string{0} vs. $string[0];
- # and ## Operators in C ?
- Equality Operators: == and != in C++
- Increment and decrement operators in Java
- Relational and Logical Operators in C

Advertisements