Skip to main content
3 of 3
denoise https://meta.stackexchange.com/q/131009/997587
starball
  • 41.1k
  • 20
  • 131
  • 699

Switch-case statement works like if-elseif.
As well as you can use regex for if-elseif, you can also use it in switch-case.

if (preg_match('/John.*/', $name)) {
    // do stuff for people whose name is John, Johnny, ...
}

can be coded as:

switch $name {
    case (preg_match('/John.*/', $name) ? true : false) :
        // do stuff for people whose name is John, Johnny, ...
        break;
}
bourbaki