Skip to main content

Command Palette

Search for a command to run...

How to use β€œmatch” with PHP 8 🎯

`match` expression with PHP 8.0

Updated
β€’1 min read
How to use β€œmatch” with PHP 8 🎯
P

I'm Pierre-Henry Soria. A passionate full stack engineer, building things that matter, making a real impact on the world.

Really like to take care of others and manage my workflow based on productivity methodologies.

Open to fast-paced changes with rapidly evolving business and technologies. I'm always thirsty to learn and undertake new exciting things and thrilling challenges.

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!',
};

πŸ’« Side Projects on GitHub πŸ‘‰ https://github.com/pH-7

More from this blog

Super Passionate Software Engineer

37 posts

Pierre-Henry Soria. A super passionate & enthusiastic software engineer! πŸš€ True cheese & chocolate lover! πŸ˜‹ πŸ‘‰ Reach me at https://ph7.me πŸ’«