Php match values ​​between 2 arrays

Guys, I have a very difficult situation, I'm not sure if I take the right approach correctly or not. I'm trying to match values ​​between two arrays and then run if else statement ... here goes what I'm trying to do

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

I want to check where the values ​​of these two arrays match each other. both php and html are common to both, and also where they do not match.

thanks

+7
source share
4 answers

Do you mean the intersection?

+9
source

array_intersect

and

array_diff

should do what you want.

+7
source

This is your need:

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

result:

 Array ( [0] => html [1] => php ) 
+6
source

To get both intersecting elements of an array and different elements, use array_diff () and array_intersect () .

+4
source

All Articles