Bird
0
0

Find the error in this PHP code snippet:

medium📝 Debug Q14 of 15
PHP - Type Handling
Find the error in this PHP code snippet:
$x = '10';
if ($x = 10) {
echo 'Match';
} else {
echo 'No Match';
}
AUsing assignment (=) instead of comparison (==) in if condition
BMissing semicolon after echo statement
CUsing double quotes instead of single quotes
DVariable $x is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check if condition operator

    The condition uses = which assigns 10 to $x instead of comparing.
  2. Step 2: Understand effect of assignment in if

    Assignment returns 10 (truthy), so 'Match' always prints, ignoring original $x value.
  3. Final Answer:

    Using assignment (=) instead of comparison (==) in if condition -> Option A
  4. Quick Check:

    Assignment in if condition = Using assignment (=) instead of comparison (==) in if condition [OK]
Quick Trick: Use == or === for comparison, not = [OK]
Common Mistakes:
  • Confusing = with == in conditions
  • Thinking missing semicolon causes error here
  • Assuming quotes affect comparison operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes