Bird
0
0

Identify the problem in this PHP code:

medium📝 Debug Q7 of 15
PHP - Operators
Identify the problem in this PHP code:
$x = true;
if ($x ||) {
echo 'Yes';
}
AVariable $x is not boolean
BSyntax error due to dangling || operator
CMissing semicolon after echo
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check the if condition syntax

    The condition ends with || without a second operand, causing syntax error.
  2. Step 2: Understand PHP syntax rules

    Logical operators require two operands; dangling || is invalid.
  3. Final Answer:

    Syntax error due to dangling || operator -> Option B
  4. Quick Check:

    Logical operators need two operands [OK]
Quick Trick: Logical operators need two operands [OK]
Common Mistakes:
  • Leaving operator without second operand
  • Assuming code runs with syntax error
  • Ignoring PHP error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes