Bird
0
0

What is wrong with this PHP code?

medium📝 Debug Q6 of 15
PHP - Type Handling
What is wrong with this PHP code?
$num = '10';
if ($num = 10) {
echo 'Matched';
}
AVariable $num is not declared
BAssignment used instead of comparison in if condition
CMissing semicolon after echo statement
DUsing double quotes instead of single quotes
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the if condition

    The condition if ($num = 10) assigns 10 to $num instead of comparing it.
  2. Step 2: Identify correct comparison operator

    Comparison requires == or ===, not = which is assignment.
  3. Final Answer:

    Assignment used instead of comparison in if condition -> Option B
  4. Quick Check:

    Use == or === for comparison, not = [OK]
Quick Trick: Use == or === in conditions, not = [OK]
Common Mistakes:
  • Using = instead of == in conditions
  • Confusing assignment with comparison
  • Ignoring operator precedence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes