Bird
0
0

Find the error in this PHP code snippet:

medium📝 Debug Q6 of 15
PHP - Operators
Find the error in this PHP code snippet:
$a = true;
if ($a & true) {
echo 'Yes';
}
AIncorrect if syntax
BUse of single & instead of &&
CVariable $a not defined
DMissing semicolon after echo
Step-by-Step Solution
Solution:
  1. Step 1: Identify operator used

    The code uses single & which is bitwise AND, not logical AND.
  2. Step 2: Correct operator for logical condition

    Logical AND requires && to combine boolean expressions.
  3. Final Answer:

    Use of single & instead of && -> Option B
  4. Quick Check:

    Logical AND needs &&, not & [OK]
Quick Trick: Use && for logical AND, & is bitwise [OK]
Common Mistakes:
  • Using & instead of &&
  • Assuming & works as logical AND
  • Ignoring operator precedence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes