Bird
0
0

What will be the output when accessing this PHP file via a browser?

medium📝 Predict Output Q4 of 15
PHP - Basics and Execution Model
What will be the output when accessing this PHP file via a browser?
<?php
$time = 10;
if ($time < 12) {
  echo 'Good morning';
} else {
  echo 'Good afternoon';
}
?>
AGood evening
BGood afternoon
CGood morning
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    The variable $time is set to 10, which is less than 12.
  2. Step 2: Evaluate the condition

    Since $time < 12 is true, the script prints 'Good morning'.
  3. Final Answer:

    Good morning -> Option C
  4. Quick Check:

    $time = 10 < 12, so output is 'Good morning' [OK]
Quick Trick: Check variable values and conditions carefully [OK]
Common Mistakes:
  • Assuming date('H') returns 12-hour format
  • Confusing output strings
  • Ignoring server time zone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes