我有两个数组。我想比较两个数组集合。
数组集合
Array
(
[0] => Array
(
[id] => 334
)
)
Array
(
[1] => Array
(
[id] => 338
)
)
Array
(
[2] => Array
(
[id] => 343
)
)
Array
(
[3] => Array
(
[item_id] => 376
)
)
B阵列集合:
Array
(
[0] => Array
(
[id] => 343
)
)
Array
(
[1] => Array
(
[id] => 334
)
)
输出:
Exists
Not
Exists
Not
答案 0 :(得分:1)
使用array_diff()和array_intersect()来实现
答案 1 :(得分:0)
在第一个数组成员之间进行迭代,并使用in_array()函数检查每个成员的第二个数组。
$FirstArray = array(1, 2, 3, 4, 5);
$SecondArray = array(1, 3);
for($i = 0; $i < count($FirstArray); $i++){
if(in_array($FirstArray[i], $SecondArray)){
echo "Exists" . PHP_EOL;
}
else {
echo "Doesn't Exists!" . PHP_EOL;
}
}
应该输出
Exists
Doesn't Exists!
Exists
Doesn't Exists!
Doesn't Exists!