Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Conditional Statements
What will be the output of this PHP code?
$a = 5;
if ($a > 3) {
echo 'Yes';
} else {
echo 'No';
}
ANo
BYes
CNothing
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition $a > 3

    Since $a is 5, the condition 5 > 3 is true.
  2. Step 2: Determine which block runs

    Because the condition is true, the code inside the if block runs, printing 'Yes'.
  3. Final Answer:

    Yes -> Option B
  4. Quick Check:

    Condition true = print 'Yes' [OK]
Quick Trick: If condition true, if block runs [OK]
Common Mistakes:
  • Choosing else output when condition is true
  • Expecting no output
  • Thinking code throws error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes