Checking if 2 arrays have at least 1 equal value

前端 未结 1 1263
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 23:20

Currently I have 2 array:

array(1, 2, 3, 4);
array(4, 5, 6, 7);

How can I check if there is at least one equal value in both of them? (The

相关标签:
1条回答
  • 2020-12-02 00:17

    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)
    }
    
    0 讨论(0)
提交回复
热议问题