The intersection of the PHP array array_intersect (), array_intersect_assoc (), and array_inte. 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 () the function returns an array (only an array worth comparing) with a common element of an intersection. the array_intersect_assoc () function binds the key value and value to compare the intersection part and the array_intersect_key () 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:
The code is as follows:
$ 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"
";
$ Num = array_intersect_assoc ($ array, $ array1 );
Print_r ($ num );
Echo"
";
$ Num = array_intersect_key ($ array, $ array1 );
Print_r ($ num );
?>
Running result:
The 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.
Struct (only array worthy of comparison), the array_intersect_assoc () function binds the key value and value, compares the intersection part together, and the array_intersect_key () function is...