我有两个一维数组:
$table1 = (9001, 9002, 9003, 9004, 9005, 9006, 9007);
$table2 = (9001, 9004, 9010);
我必须知道$ table2中的任何元素是否(或不是)在$ table 1中。
怎么做?
答案 0 :(得分:9)
$array1 = array(9001, 9002, 9003, 9004, 9005, 9006, 9007);
$array2 = array(9001, 9004, 9010);
$result = array_intersect($array1, $array2);
输出
Array
(
[0] => 9001
[3] => 9004
)
答案 1 :(得分:2)
使用array_intersect
。它返回两个数组中的值数组。
$match = array_intersect($table1, $table2);
答案 2 :(得分:2)
$elements_in_common = array_intersect($table1,$table2);