Checking if 2 arrays have at least 1 equal value [duplicate]

array_intersect()

returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved

$a = array(1, 2, 3, 4);
$b = array(4, 5, 6, 7);
$c = array_intersect($a, $b);
if (count($c) > 0) {
    var_dump($c);
    //there is at least one equal value
}

you get

array(1) {
  [3]=>
  int(4)
}

Leave a Comment