DEV Community

Cover image for How to use “match” with PHP 8 🎯
Pierre-Henry Soria ✨
Pierre-Henry Soria ✨

Posted on • Edited on

2 1 1 1 1

How to use “match” with PHP 8 🎯

Let's use match expression with PHP 8.0 💪 Lets' see when to use it and why it can have advantages over the old good switch statement.
match will indeed make your code cleaner, less verbose and easier to read 💥

Furthermore, with the “https://php.watch/versions/8.0/match-expression” expression, you can have multiple matching conditions separated by commas, like

$sMessage = match ($sDayPrefix) {
  'Sat', 'Sun' => 'Enjoy your weekend!',
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of DataStax

AI Agents Made Easy with Langflow

Connect models, vector stores, memory and other AI building blocks with the click of a button to build and deploy AI-powered agents.

Get started for free

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay