1<?php
2$a1 = array("a"=>"red", "b"=>"green", "c"=>"blue", "d"=>"yellow");
3$a2 = array("e"=>"red", "f"=>"green", "g"=>"blue");
4
5$result = array_intersect($a1, $a2);
6print_r($result); //Array ( [a] => red [b] => green [c] => blue )
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);
1<?php
2 $array1 = array("a" => "verde", "vermelho", "azul");
3 $array2 = array("b" => "verde", "amarelo", "vermelho");
4 $result = array_intersect($array1, $array2);
5 print_r($result); // Array ( [a] => verde [0] => vermelho )
6?>
1PHP function array_intersect(array $array1, array $array2, array ...$_) int[]
2-----------------------------------------------------------------------------
3Computes the intersection of arrays
4
5Parameters:
6array--$array1--The array with main values to check.
7array--$array2--An array to compare values against.
8array--...$_--[optional]
9Returns: an array containing all of the values in array1 whose values exist in all of the parameters.