PHP 使用 or 运算符根据值数组检查变量
PHP check variable against an array of values with or operator
所以我有这个值数组
$veg = array('tomatoes', 'potatoes');
如何使用 "or" 运算符
对照我的变量检查此数组
类似
if if ($veggies == ('tomatoes' || 'potatoes')) {
...
}
但我不知道如何在那里使用我的阵列
使用in_array
函数:
if (in_array($veggies, $veg)) {
// do something
}
所以我有这个值数组
$veg = array('tomatoes', 'potatoes');
如何使用 "or" 运算符
对照我的变量检查此数组类似
if if ($veggies == ('tomatoes' || 'potatoes')) {
...
}
但我不知道如何在那里使用我的阵列
使用in_array
函数:
if (in_array($veggies, $veg)) {
// do something
}