How can i find the intersection of two arrays in php?
(PHP 4 >= 4.0.1, PHP 5, PHP 7, PHP 8) Show array_intersect — Computes the intersection of arrays Descriptionarray_intersect(array Parametersarray The array with master values to check. arrays Arrays to compare values against. Return Values Returns an array containing all of the values in Changelog
ExamplesExample #1 array_intersect() example
The above example will output: Array ( [a] => green [0] => red ) Notes
See Also
stuart at horuskol dot co dot uk ¶ 14 years ago
= array(2, 4, 6, 8, 10, 12); Niels ¶ 16 years ago
Shawn Pyle ¶ 13 years ago
sapenov at gmail dot com ¶ 17 years ago
blu at dotgeek dot org ¶ 17 years ago
[0] = array('John Doe', 'PHP Book'); yuval at visualdomains dot com ¶ 7 years ago
= range(1,1000000); dml at nm dot ru ¶ 11 years ago
matang dot dave at gmail dot com ¶ 7 years ago
Oto Brglez ¶ 13 years ago
= array();
info at iridsystem dot it ¶ 7 years ago
Esfandiar -- e.bandari at gmail dot com ¶ 14 years ago
theking at king dot ma ¶ 4 months ago
Anonymous ¶ 1 year ago
Yohann ¶ 12 years ago
Malte ¶ 14 years ago
nthitz at gmail dot com ¶ 16 years ago
t dot wiltzius at insightbb dot com ¶ 18 years ago
anbolb at boltblue dot com ¶ 18 years ago
terry(-at-)shuttleworths(-dot-)net ¶ 16 years ago
tom p ¶ 16 years ago
caffinated ¶ 9 years ago
ben at kazez dot com ¶ 18 years ago
Mike Block ¶ 9 years ago
david at audiogalaxy dot com ¶ 21 years ago
gary ¶ 13 years ago
$numbers;
meihao at 126 dot com ¶ 8 years ago
Ehsan.Chavoshi.com ¶ 3 years ago
zoolyka at gmail dot com ¶ 3 years ago
= range(1, 250000); ram ¶ 4 years ago
karl at libsyn dot com ¶ 13 years ago
findMatchingArray( $needle, $haystack ) {
189780 at gmail dot com ¶ 12 years ago
jake ¶ 5 years ago
What is array intersect?The intersection of two arrays is a list of distinct numbers which are present in both the arrays. The numbers in the intersection can be in any order. For example. Input: A[] = {1,4,3,2,5, 8,9} , B[] = {6,3,2,7,5}
How can I find the difference between two arrays in PHP?The array_diff() function compares the values of two (or more) arrays, and returns the differences. This function compares the values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc.
How do you check if an array exists in another array PHP?The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.
How can I get unique values from two arrays in PHP?The array_diff() (manual) function can be used to find the difference between two arrays: $array1 = array(10, 20, 40, 80); $array2 = array(10, 20, 100, 200); $diff = array_diff($array1, $array2); // $diff = array(40, 80, 100, 200);
|