我想使用php检查数组2中是否存在数组1,我尝试了in_array,但我没有得到任何结果:/
array(
(int) 0 => '2',
(int) 1 => '3'
)
array(
(int) 0 => (int) 1,
(int) 1 => (int) 2,
(int) 2 => (int) 3
)
请有人可以提供帮助:)。
谢谢!
答案 0 :(得分:0)
array_intersect将为您服务。试试这个:
$array1 = array(
(int) 0 => '2',
(int) 1 => '3'
)
$array2 = array(
(int) 0 => (int) 1,
(int) 1 => (int) 2,
(int) 2 => (int) 3
)
$result = array_intersect($array1, $array2);
if($result)
{
// exists
}
else
{
// not exists
}
答案 1 :(得分:0)
$array1 = [0=>'2',1=>'3'];
$array2 = [1,2,3];
echo "<PRE>",var_dump(array_intersect($array1,$array2)),"</PRE>";
输出:
array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "3"
}