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