Php two array intersection difference set array_intersect -- calculate the array intersection description arrayarray_intersect (arrayarray1, arrayarray2 [, array...]) array_intersect () returns an array that contains the intersection difference set of both arrays in php in array1.
Array_intersect -- describe the intersection of arrays
Array array_intersect (array array1, array array2 [, array...])
Array_intersect () returns an array containing all values that appear in the array of all other parameters at the same time in array1. Note that the key name remains unchanged.
This makes $ result an array (1 => "blue ");. Values that appear multiple times in $ array1 are treated as the same.
Note: The two units are considered the same only when (string) $ elem1 === (string) $ elem2. That is to say, when the expression of the string is the same.
Note: This function only checks one dimension in a multi-dimensional array. Of course, you can use array_diff ($ array1 [0], $ array2 [0]); to check deeper dimensions.
Array_diff_assoc -- calculate the array's difference set with index check
Array_diff_assoc () returns an array that contains all values in the array of array1 but not in any other parameter. Note that, unlike array_diff (), the key name is also used for comparison.
/* The result is:
Array
(
[B] => brown
[C] => blue
[0] => red
)
*/
?>
In the above example, we can see that the key-value pair "a" => "green" exists in both arrays, so it is not in the output of this function. In contrast, the key-value pair 0 => "red" appears in the output because the key name of "red" in the second parameter is 1.
The two values in key => value are considered equal only when (string) $ elem1 === (string) $ elem2. That is to say, the use of strict check, the expression of the string must be the same.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service