本文介绍了PHP比较两个数组,并得到匹配的值没有区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较两个数组,并得到仅存在两个阵列上,但不幸的价值观,我无法找到使用权阵列功能...
我找到了和array_diff()
功能:的
但它的两个阵列的区别。
示例:
$ ARRAY1 =阵列(** **阿尔法,欧米茄,** **布拉沃,** **查理,**三角洲* *,** foxfrot **);
$ =数组2 array(\"**alpha**\",\"gamma\",\"**bravo**\",\"x-ray\",\"**charlie**\",\"**delta**\",\"halo\",\"eagle\",\"**foxfrot**\");
预期输出:
$结果=阵列(** **阿尔法,** **布拉沃,** **查理,** **三角洲, ** foxfrot **);
解决方案
简单,使用来代替:
$结果= array_intersect($数组1,$数组2);
I'm trying to compare two arrays and get only the values that exist on both arrays but, unfortunately, I can't find the right array function to use...
I found the array_diff()
function: http://php.net/manual/en/function.array-diff.php
But it's for the difference of the both arrays.
Example:
$array1 = array("**alpha**","omega","**bravo**","**charlie**","**delta**","**foxfrot**");
$array2 = array("**alpha**","gamma","**bravo**","x-ray","**charlie**","**delta**","halo","eagle","**foxfrot**");
Expected Output:
$result = array("**alpha**","**bravo**","**charlie**","**delta**","**foxfrot**");
解决方案
Simple, use array_intersect()
instead:
$result = array_intersect($array1, $array2);
这篇关于PHP比较两个数组,并得到匹配的值没有区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!