比较两个数组并获得所有差异 [英] Compare two array and get all differences
本文介绍了比较两个数组并获得所有差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个这样的数组.
$array1=array(1,2,3,4,5,7);
$array2=array(1,2,3,4,5,6);
因此,输出应该在两个数组中带来差异.
So, the output should bring the difference in both arrays.
输出应该是.
1,2,3,4,5->这些数字同时存在于两个数组中,因此应将其忽略.
1,2,3,4,5 -> These numbers exist in both arrays, so these should be ignored.
7和6->这些数字在两个数组中都不常见,因此我需要在数组中使用这些值.
7 and 6 -> These numbers are the un-common in both arrays, so I need these values in array.
输出应为7& 6.
The output should be 7 & 6.
帮帮我.我试过array_diff
和其他数组元素.
Help me out. I have tried array_diff
and other array elements.
推荐答案
尝试一下
array_merge(array_diff($array1,$array2),array_diff($array2,$array1))
这篇关于比较两个数组并获得所有差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文