---
title: 'PHP Switch vs Match: Visual Difference'
source: 'https://youtube.com/watch?v=Bj2G7gBCWOE'
video_id: 'Bj2G7gBCWOE'
date: 2026-08-14
duration_sec: 45
---

# PHP Switch vs Match: Visual Difference

> Source: [PHP Switch vs Match: Visual Difference](https://youtube.com/watch?v=Bj2G7gBCWOE)

## Summary

This video demonstrates how to visually compare PHP's `switch` and `match` expressions, using a real-world example from an open-source project. It shows how PHPStorm can automatically convert a verbose `switch` statement into a more concise `match` expression, making the code shorter and more readable.

### Key Points

- **Switch statement example** [00:00] — The video starts with an example from an open-source project where a `switch` statement has many cases, each calling a function, making the code long and vertically stretched.
- **PHPStorm conversion suggestion** [00:13] — PHPStorm underlines the `switch` statement and suggests it can be converted to a `match` expression, offering a quick refactoring option.
- **Result of conversion** [00:26] — After clicking the suggestion, the code is transformed from three lines per case to one line per case, making it more readable and shorter, fitting on the screen of a YouTube short.

### Conclusion

The video shows that using `match` instead of `switch` can significantly reduce code length and improve readability, and PHPStorm provides an easy way to perform this refactoring.

## Transcript

Let me show you the visual difference of PHP operator switch and match. So I found this example in one open source project with switch, case, a lot of cases, and each case calls some function.
So the code is really long vertically. Can it be transformed to match? And phpStorm can help us with that really quickly. So there's underlined switch statement with message that it can be converted.
We'll just click here, and here's the result. So instead of three lines for every option, we have one line, which is even more readable, you would argue. And now that code vertically is shorter, even fitting on the screen of this YouTube short.
For longer PHP and Laravel videos, subscribe to my channel, Laravel Daily.
