Common array functions in php (3) (array_intersect (), array_intersect_key (), array_intersect_assoc (), round (), round (), and arrayintersectukey
The five functions that obtain the intersection have five corresponding functions that obtain the difference set.I am a link.
Array_intersect ($ arr1, $ arr2 );
// Obtain the ArraySame Key ValueIntersection
Array_intersect_key ($ arr1, $ arr2 );
// Obtain the ArraySame key nameIntersection
Array_intersect_assoc (same as above );
// Obtain the ArraySame Key ValueIntersection
Array_intersect_uassoc (same as above, 'custom callback function ');
// UseCustom callback functionTo obtain the ArraySame Key ValueIntersection
Array_intersect_ukey (same as above, custom callback function );
// UseCustom callback functionTo obtain dataSame key nameIntersection
1 $ arr1 = array ('R' => 'red', 'U' => 'Blue ', 'G' => 'green ', 'B' => 'black'); 2 $ arr2 = array ('R' => 'red', 'B' => 'blue '); 3/*********** array_intersect (calculate the intersection of the same key value in the array) * ***************/4 $ arrIntersect = array_intersect ($ arr1, $ arr2); 5 var_dump ($ arrIntersect ); // => array (2) {["r"] => string (3) "red" ["u"] => string (4) "blue"} 6 7/*********** array_intersect_key (calculate the intersection of the same key names in the array) * ***************/8 $ arrIntersectKey = array_intersect_key ($ arr1, $ arr2); 9 var_dump ($ arrIntersectKey ); // => array (2) {["r"] => string (3) "red" ["B"] => string (5) "black"} 10 11/*********** array_intersect_assoc (calculate the intersection of the same key name and the same key value in the array) * ***************/12 $ arrIntersectAssoc = array_intersect_assoc ($ arr1, $ arr2); 13 var_dump ($ arrIntersectAssoc ); // => array (1) {["r"] => string (3) "red"} 14 15/************ array_intersect_uassoc (using a custom callback function to calculate the intersection of the same key and value of the array with the same key name) * ***************/16 $ arrIntersectUassoc = array_intersect_uassoc ($ arr1, $ arr2, 'Arr _ intersect_uassoc_func '); 17 var_dump ($ arrIntersectUassoc); // => array (1) {["r"] => string (3) "red"} 18 19 function arr_intersect_uassoc_func ($, $ B) {20 if ($ a ===$ B) 21 return 0; 22 elseif ($ a> $ B) 23 return 1; 24 else25 return-1; 26} 27 28/*********** array_intersect_ukey (use a custom callback function to calculate the intersection of the same key names in the array) * ***************/29 $ arrIntersectUkey = array_intersect_ukey ($ arr1, $ arr2, 'Arr _ intersect_ukey_func '); 30 var_dump ($ arrIntersectUkey); // => array (2) {["r"] => string (3) "red" ["B"] => string (5) "black"} 31 32 function arr_intersect_ukey_func ($ k1, $ k2) {33 if ($ k1 = $ k2) 34 return 0; 35 elseif ($ k1> $ k2) 36 return 1; 37 else38 return-1; 39}