Returns an array of common elements of the intersection (just the array is worth comparing), the ARRAY_INTERSECT_ASSOC () function is to bind the key value and value, compare the intersection part, the Array_intersect_key () function is to compare the key values of the two arrays. Returns an array of key value intersections.
But the actual application also encountered some minor problems, is as follows:
Instance:
Copy Code code as follows:
? Php
$array = Array ("Red" => "red", "green" => "Red4", "Red15" => "Red",7=> "level", "Width" => "Red", "azzzz1" = > "Art", "Peak" =>158);
$array 1 = Array ("Red" => "Red2", "Greena" => "Red", "Red15" => "Red",7=> "level", "Width" => "Red", "azzzz" = > "Art", "Peak" =>158);
$num = Array_intersect ($array, $array 1);
Print_r ($num);
echo "<br/>";
$num = Array_intersect_assoc ($array, $array 1);
Print_r ($num);
echo "<br/>";
$num = Array_intersect_key ($array, $array 1);
Print_r ($num);
?>
Run Result:
Copy Code code 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)
Summarize:
The 1.array_intersect () function compares only the array values, but also returns "red" when compared to "red" and "Red2", whereas it does not return "RED2";
The 2.ARRAY_INTERSECT_ASSOC () function compares the value of an array with a key value and does not exist in a array_intersect case, and is suitable for a more rigorous comparison;
The 3.array_intersect_key () function is used to compare the intersection of two array key values, not just the key values, but the key values and the corresponding array values.