Skip to content
Advertisement

php switch statement with wildcard in the string

I would like to have a switch statement with both literal cases and cases with a wildcard in the string:

JavaScript

Of course the * will be taken literally here cause I define it as a string, so this does not work, but you know what I would like to accomplish: for the A, B and D cases the numbers can be whatever (*). Maybe with preg_match this is possible but that really blows my head. I Googled, I really did.

Advertisement

Answer

You can do it with switch, of course only, if it really best approach. Very long switch list of cases is a headache…

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement