1$array1 = [1, 2];
2$array2 = [2, 3, 4];
3$commonValue = array_intersect($array1, $array2);
4//$commonValue = 2
5// If you have X number of arrays you can do:
6$array1 = [1, 2];
7$array2 = [2, 3, 4];
8$arrayOfArrays = [$array1, $array2];
9$commonValue = array_intersect(...$arrayOfArrays);
1function getArraysIntersection(a1,a2){
2 return a1.filter(function(n) { return a2.indexOf(n) !== -1;});
3}
4var colors1 = ["red","blue","green"];
5var colors2 = ["red","yellow","blue"];
6var intersectingColors=getArraysIntersection(colors1, colors2); //["red", "blue"]
7
8