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;
}
Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…