2

2 つの配列の値を一致させようとしています。一致する値が存在する場合、true を出力します。おそらく array_intersect 関数を考えていますか? 非常に不確かです!どんな助けでも大歓迎です!

基本的に、このボックスには収まらない 2 つの 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

はい、配列が交差します。次のようなことを試してください:

$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 に答える