Bird
0
0

What is the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - Conditional Statements
What is the output of this PHP code?
$score = 75;
$grade = ($score >= 60) ? 'Pass' : 'Fail';
echo $grade;
AFail
BPass
C75
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition ($score >= 60)

    The score is 75, which is greater than or equal to 60, so the condition is true.
  2. Step 2: Determine the ternary result

    Since the condition is true, the expression returns 'Pass'.
  3. Final Answer:

    Pass -> Option B
  4. Quick Check:

    True condition returns true value = Pass [OK]
Quick Trick: True condition returns first value before colon [OK]
Common Mistakes:
  • Choosing false value
  • Printing variable instead of result
  • Syntax errors in ternary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes