PHP tip: Use a regular expression in a switch statement

I came across this nugget while trying to rapidly prototype some new functionality for one of my clients. The client wanted specific artwork to show up for a subset of related items. The prototype has worked out so well, that I haven't yet had to go back add a flag field to the underlying database table. One of the things I had going for me was that the SKUs I needed to identify followed a rigid naming convention. I didn't want to update the switch statement each time a new SKU is added, so instead of this:

What others are saying...

An excellent and very practical tip. Thank you for sharing. Here's another fun, although less practical usage. Switch against TRUE, and use the fall through to grant access in a hierarchy without repeating your code for each role and avoiding a nasty if block.