PHP TutorialLesson 18Free preview
PHP Match
This lesson is part of PHP · All levels
Summary
Match is a new feature in PHP 8 that is similar to the switch, but more stringent and expressive. Match makes a strict comparison (===), requires no break, and the result can be used immediately as a value. If no match is available, the match will throw an exception if no default is provided.
Key points
- Match was introduced in PHP 8.0
- Match uses strict comparison (===) and does not require a break
- Match can return the value so it can be instantly echoed.
- If there's no match, the match throws the UnhandledMatchError
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.