Php 使用if-then-else语句比较动态数组

Php 使用if-then-else语句比较动态数组,php,arrays,compare,Php,Arrays,Compare,在我的代码中,我要替换以下内容: if($file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE"){} else{} 可以在更通用的配置文件中更改类似的内容: $domains_to_exclude="VALUE,VALUE,VALUE,VALUE"; 两个数组的值都会发生变化。我想做的是,如果$file['domain']与doma

在我的代码中,我要替换以下内容:

if($file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE" || $file['domain']=="VALUE"){}
else{}
可以在更通用的配置文件中更改类似的内容:

$domains_to_exclude="VALUE,VALUE,VALUE,VALUE";
两个数组的值都会发生变化。我想做的是,如果
$file['domain']
domains\u to\u exclude
的值匹配,则跳过它

我正朝着正确的方向努力,尝试这样的事情。到目前为止,我还没有取得任何成功

$myArray = explode(',', $domains_to_exclude);
$count = count($file);
for ($i=1; $i<$count; $i++)
{
  if ($myArray[$i] !== $file['domain'])
  {
    $domain=$file['domain'];
    $domainn = str_replace("", "", $domain);
    echo'<option value="'.$domain.'">'.$domainn.'</option>';
  }
  else {}
}
$myArray=explode(“,”,$domains\u to\u exclude);
$count=计数($file);

对于($i=1;$i您可以执行以下操作:

$domains_to_exclude = array(...); //make an array of your "VALUES"

$file = array('foo', 'bar'); // your $file array

if(count(array_intersect($domains_to_exclude, $file)) > 0){
    // at least a match was found
 }

您可以这样做:

$domains_to_exclude = array(...); //make an array of your "VALUES"

$file = array('foo', 'bar'); // your $file array

if(count(array_intersect($domains_to_exclude, $file)) > 0){
    // at least a match was found
 }
in_数组($str,$arr)检查$arr中的任何值是否等于$str

另外,如果else为空,则不必在那里设置else块,但它也不会对代码产生负面影响

in_数组($str,$arr)检查$arr中的任何值是否等于$str


另外,如果else为空,则不必将其阻塞在那里。但它也不会对代码产生负面影响。

in_array
函数。
in_array
函数。