Answers for "array intersect"

PHP
1

array intersect

array_intersect(array $array, array ...$arrays): array

/* Returns an array containing all of the values in array whose 
   values exist in all of the parameters. */
Posted by: Guest on September-23-2021
2

php get intersection of two arrays

$array1 = [1, 2];
$array2 = [2, 3, 4];
$commonValue = array_intersect($array1, $array2);
//$commonValue = 2
// If you have X number of arrays you can do:
$array1 = [1, 2];
$array2 = [2, 3, 4];
$arrayOfArrays = [$array1, $array2];
$commonValue = array_intersect(...$arrayOfArrays);
Posted by: Guest on May-30-2020

Browse Popular Code Answers by Language