The intersection of two arrays can be implemented using Array_intersect (), Array_inersect_assoc,array_intersect_key, where the Array_intersect () function is the intersection of two numbers, Returns an array of common elements for the intersection (only the array is worth comparing), the ARRAY_INTERSECT_ASSOC () function is binding the key and value, and the Array_intersect_key () function compares the key values of two arrays. Returns an array of key-value intersections.
But the actual application also encountered some small problems, is as follows:
Instance:
"Red", "green" and "red4", "Red15" and "Red",7=> "level", "Width" = "Red", "azzzz1" and "Art", "Peak" =>158); $array 1 = Array ("Red" = "Red2", "Greena" and "Red", "Red15" and "Red",7=> "level", "Width" = "Red", "azzzz" = > "Art", "Peak" =>158); $num = Array_intersect ($array, $array 1); Print_r ($num); echo "
"; $num = Array_intersect_assoc ($array, $array 1); Print_r ($num); echo "
"; $num = Array_intersect_key ($array, $array 1); Print_r ($num);?>
Operation Result:
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 comparison of the 1.array_intersect () function only compares the values of the array, and there is a "red" when compared with "red" and "Red2", whereas the "Red2" is not returned;
The 2.ARRAY_INTERSECT_ASSOC () function compares the value of an array with a key value, and there is no array_intersect, which is appropriate for a more rigorous comparison;
The 3.array_intersect_key () function is useful for comparing the intersection of two array key values, returning not only the key value, but the key value and the corresponding array value.
http://www.bkjia.com/PHPjc/478803.html www.bkjia.com true http://www.bkjia.com/PHPjc/478803.html techarticle the intersection of two arrays can be implemented using Array_intersect (), Array_inersect_assoc,array_intersect_key, where the Array_intersect () function is the intersection of two numbers, Return a cross ...