当然
你可以使用in_array
对于这种类型的支票,类似这样的
if (in_array($string, [\'apple\', \'banana\', \'kiwi\'])) { // keep adding as many as you need
$Detail = false;
$bShowNew = true;
}
如果数组变大,可以创建一个包含该数组的变量
$allowed = [
\'apple\',
\'banana\',
\'kiwi\'
// etc...
];
if (in_array($string, $allowed)) { // keep adding as many as you need
$Detail = false;
$bShowNew = true;
}
这将完全相同,但更干净,更容易阅读