- $array 1 = Array ("A" = "green", "Red", "blue");
- $array 2 = Array ("b" = "green", "yellow", "red");
- $result = Array_intersect ($array 1, $array 2);
- ?>
Copy Code
The example above will output: Array ([a] = green[0] + red)
2.ARRAY_INTERSECT_ASSOC () returns a key-value pair with the same key and value in all arrays, based on the previous function.
Example:
- $array 1 = Array ("A" = "green", "b" = "Brown", "c" = "blue", "Red");
- $array 2 = Array ("A" = "green", "yellow", "red");
- $result _array = Array_intersect_assoc ($array 1, $array 2);
- ?>
Copy Code
The example above will output: Array ([a] = green)
3.array_diff () carries multiple arrays, returning a new array of all the values in the first array that are not in the following array, and the corresponding key is taken from the first array.
Example:
-
$array 1 = Array ("A" = "green", "Red", "Blue", "Red");
- $array 2 = Array ("b" = "green", "yellow", "red");
- $result = Array_diff ($array 1, $array 2);
-
Print_r ($result);
- ?>
Copy Code
The example above will output: Array ([1] = blue)
4.array_diff_assoc () on the basis of the previous function, it is necessary to match not only the value but also the key.
Example:
- $array 1 = Array ("A" = "green", "b" = "Brown", "c" = "blue", "Red");
- $array 2 = Array ("A" = "green", "yellow", "red");
- $result = Array_diff_assoc ($array 1, $array 2);
- ?>
Copy Code
The example above will output: Array ( = = Brown[c] = blue[0] = red)
|