Bird
0
0

Which of the following is a key difference between match and switch in PHP 8?

easy📝 Conceptual Q2 of 15
PHP - Conditional Statements
Which of the following is a key difference between match and switch in PHP 8?
A<code>switch</code> requires a default case, <code>match</code> does not
B<code>switch</code> supports returning values, <code>match</code> does not
C<code>match</code> allows fall-through between cases, <code>switch</code> does not
D<code>match</code> supports strict type comparisons, <code>switch</code> does not
Step-by-Step Solution
Solution:
  1. Step 1: Compare type checking in match vs switch

    Match uses strict type and value comparison (===), while switch uses loose comparison (==).
  2. Step 2: Verify other options

    Switch allows fall-through, match does not. Match returns values, switch can but less cleanly. Default case is optional in both.
  3. Final Answer:

    match supports strict type comparisons, switch does not -> Option D
  4. Quick Check:

    Match vs Switch = Strict type in match [OK]
Quick Trick: Match uses strict comparison (===), switch uses loose (==) [OK]
Common Mistakes:
  • Thinking switch requires default case
  • Believing match allows fall-through
  • Assuming match cannot return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes