How does PHP 8's match expression differ from a switch statement?
A
It works only with integer conditions
B
It needs a break after every case arm
C
It uses strict comparison and returns a value
Correct answer
D
It uses loose comparison and falls through
Correct answer
C. It uses strict comparison and returns a value
15 views
⚔️
Challenge a friend on PHP
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
match compares with ===, has no fall-through, returns a value directly and throws UnhandledMatchError when no arm matches, so it is safer and more concise than switch.
Reference
Asked in: NTS, PHP Developer Interviews
Doubts & discussionNot sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ In PHP 7+, what does $name = $_GET['name'] ?? 'Guest'; do? Next MCQ › In PHP, what does the spaceship operator expression 3 <=> 7 return?