Skip to main content
1 of 3
user avatar
user avatar

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 codded as

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

Hope this help.

bourbaki