php PHP匹配2个数组之间的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8038989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:50:05  来源:igfitidea点击:

Php match values between 2 arrays

phparrays

提问by Aman Virk

Guys i have a very awkward situation here , i am not sure whether am i taking a right approach or not.. i am trying to match the values between 2 arrays and then running if else statement... here's goes what i am trying to do

伙计们,我在这里遇到了非常尴尬的情况,我不确定我是否采取了正确的方法..我正在尝试匹配 2 个数组之间的值,然后运行 ​​if else 语句......这就是我想要做的做

$array1 = array('html','php','js','css');
$array2 = array('php','python','html','java');

what i want is to make a check where the values of these 2 arrays matches to each other. like php and html is common in both and also where it doesn't match.

我想要的是检查这两个数组的值在哪里相互匹配。像 php 和 html 在两者中都很常见,也有不匹配的地方。

Thanks

谢谢

回答by CodeCaster

You mean like an intersection?

你的意思是像一个十字路口

回答by Kannika

It's your need:

这是你的需要:

$result = array_intersect($array1, $array2);
print_r($result);

the result is:

结果是:

Array
(
    [0] => html
    [1] => php
)

回答by DTest

array_intersect

数组相交

and

array_diff

数组差异

should do what you want.

应该做你想做的。

回答by Prydie

To get both the intersecting elements of the array and the differing elements use both array_diff()and array_intersect().

要获取数组的相交元素和不同元素,请同时使用array_diff()array_intersect()