Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Conditional Statements
What will be the output of this PHP code?
$value = '5';
$result = match($value) {
5 => 'integer five',
'5' => 'string five',
default => 'unknown',
};
echo $result;
Ainteger five
Bunknown
CError
Dstring five
Step-by-Step Solution
Solution:
  1. Step 1: Understand strict comparison in match

    Match uses strict comparison (===), so '5' (string) does not equal 5 (integer).
  2. Step 2: Find matching case

    The case '5' (string) matches the value '5', so 'string five' is returned.
  3. Final Answer:

    string five -> Option D
  4. Quick Check:

    Match uses strict comparison, so string matches string [OK]
Quick Trick: Match uses ===, so type matters in matching [OK]
Common Mistakes:
  • Assuming loose comparison like switch
  • Expecting integer case to match string value
  • Thinking default triggers here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes