我的开关和 preg_match 案例有问题我的代码是这样的
switch( $WORD ){
case ( preg_match("/^(?:.+-)?(\d+?)$/i", $WORD , $ID ) ? true : false ):
echo "valid ". $ID ." test -> " .preg_match("/^(?:.+-)?(\d+?)$/i", $WORD );
break;
default:
echo $WORD;
break;
}
这些代码适用于
$WORD = "TEST"; print => TEST
$WORD = "TEST-1"; print => valid 1 test -> 1
$WORD = "TEST-2552"; print => valid 2552 test -> 1
$WORD = "343"; print => valid 343 test -> 1
但如果$WORD
为空或$WORD = ""
情况也为真,则打印
$WORD = ""; print => valid test -> 0
我该如何解决?我试过了
case ( ( preg_match("/^(?:.+-)?(\d+?)$/i", $WORD , $ID ) == 1 ) ? true : false ):
但不起作用