Returns an array of all elements in the intersection (only the array is worth comparing). The array_intersect_assoc () function binds the key value and value to compare the intersection part and the array_intersect_key () function () A function is an array that compares the key values of two arrays and returns the intersection of key values.
However, some minor problems have also been encountered in practical applications, as shown below:
Instance:
Copy codeThe Code is as follows: <? PHP
$ Array = array ("red" => "Red", "green" => "red4", "Red15" => "Red", 7 => "Level ", "Width" => "Red", "azzzz1" => "art", "peak" => 158 );
$ Array1 = array ("red" => "Red2", "greena" => "red", "Red15" => "Red", 7 => "Level ", "Width" => "Red", "azzzz" => "art", "peak" => 158 );
$ Num = array_intersect ($ array, $ array1 );
Print_r ($ num );
Echo "<br/> ";
$ Num = array_intersect_assoc ($ array, $ array1 );
Print_r ($ num );
Echo "<br/> ";
$ Num = array_intersect_key ($ array, $ array1 );
Print_r ($ num );
?>
Running result:Copy codeThe Code is as follows: array ([red] => Red [Red15] => Red [7] => Level [Width] => Red [azzzz1] => art [peak] => 158)
Array ([Red15] => Red [7] => Level [Width] => Red [peak] => 158)
Array ([red] => Red [Red15] => Red [7] => Level [Width] => Red [peak] => 158)
Summary:
1. the array_intersect () function only compares the array values. If "Red" and "Red2" are compared, "Red" is returned. Otherwise, "Red2" is not returned ";
2. The array_intersect_assoc () function compares the array value with the key value without the case of array_intersect. This function is suitable for strict comparison;
3. The array_intersect_key () function is applicable to comparing the intersection of two array key values. instead of only the key value, it returns the key value and the corresponding array value.