2

试图匹配两个数组中的值,如果存在匹配的值,则输出为真,也许是 array_intersect 函数?很不确定!任何帮助深表感谢!

基本上有两个我不能完全放入这个盒子的 sql 查询!但是它们每个都返回一个数组 $staffExpertise 和 $moduleExpertise,但我对 php 非常陌生,对数组相交函数更加不熟悉,所以不太确定从这里做什么!

    foreach ($results as $row) {
        $staffExpertise = $row['expertise'];
    }

    foreach ($results as $row) {
        $moduleExpertise = $row['expertise'];
    }

    $arrayIntersection = array_intersect($moduleExpertise,   $staffExpertise);

    if($arrayIntersection = ){

    }
4

2 回答 2

4

是的 array intersect 做到了。尝试这样的事情:

$names_1 = array("Alice", "Bob", "Charlie", "David");
$names_2 = array("Alice", "Bruno");

$intersection = array_intersect($names_1, $names_2);

if(!empty($intersection) ){
    echo "The following item(s) exist in both arrays:"."<br>";
  foreach($intersection as $row){
      echo $row."<br>";
  }

}else{
echo "The arrays do not intersect";
}
于 2012-12-09T00:24:17.187 回答
0

尝试:

<?php
    if (in_array($Array1, $VarToCheck)) {
        $return = true;
    }elseif (in_array($Array2, $VarToCheck)){
    $return = true;
    }
?>
于 2012-12-09T00:13:55.700 回答