

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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'), "\n"; $bool = TRUE && FALSE; echo ($bool ? 'true' : 'false'); ?>
Output
This will produce the following output−
true false
- Related Questions & Answers
- Validate input: replace all ‘a’ with ‘@’ and ‘i’ with ‘!’JavaScript
- What is the meaning and usage of ‘=&’ assignment operator in PHP?
- What is the use of ‘ALL’, ‘ANY’, ’SOME’, ’IN’ operators with MySQL subquery?
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘<’ or ‘<>’ with NULL?
- Are ‘this’ and ‘super’ keywords in Java?
- Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ in C++
- Comparing ‘cubic’ and ‘linear’ 1-D interpolation using SciPy library
- How to Use ‘cat’ and ‘tac’ Commands with Examples in Linux
- How can we create MySQL stored procedures without ‘BEGIN’ and ‘END’?
- Python program to replace first ‘K’ elements by ‘N’
- Replacing ‘public’ with ‘private’ in “main” in Java
- What is the significance of ‘^’ in PHP?
- What is the benefit of MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- K-th digit in ‘a’ raised to power ‘b’ in C++
- ‘this’ keyword in C#
Advertisements