PHP Array_uintersect_assoc () function

PHP

Syntax:
array array_uintersect_assoc ($array1, $array2, $array3 ... array nth, arr_uintersect_Function)
Parameters: This function takes many parameters as above and described below:
  • $array1:this is the initial array to compare with another array. This is a required parameter.
  • $array2:This is the second array compared to the first key in the array. It is also a required parameter.
  • $array3…:Arrays are compared against the first key of the array. This is an optional parameter.
  • arr_uintersect_Function:This is a required parameter used to store a custom function. It is a string that defines a user-defined callback function and returns an integer less than, equal to, or greater than zero if the first argument is less than, equal to, or greater than the second argument.
Return value: < / b> returns values ​​of the array type that contains the first array that is present in all other arrays. If no match is found, NULL is returned.Note.array_uintersect_assoc() compares array keys, and a user-defined function compares values.Examples:
Input: $arr1 = array ("a" = > "Website", "b" = > "frontend", "c" = > "programmer"); $arr2 = array ("a" = > "Website", "b" = > "backend", "c" = > "programmer"); $arr3 = array ("a" = > "Website", "b" = > "fullstack", "c" = > "programmer"); $arr4 = array ("a" = > "Website", "b" = > "maintanance", "c" = > "Team"); Output: Array ([a] = > Website) Explanation: Only one element (website) is common in all arrays. Input: $arr1 = array ("a" = > "Software", "b" = > "Testing", "c" = > "Tool"); $arr2 = array ("a" = > "Software", "b" = > "Testing", "c" = > "Team"); Output: Array ([a] = > Software [b] = > Testing) Explanation: Two values ​​are common in both array = Software, and Testing.
The following program illustrates the array_uintersect_assoc() function in PHP:Program 1:This program uses two arrays (array1 and array2) and a custom key comparison function ( arr_uintersect_Function). < tr>  
// PHP program for the array_uintersect_assoc() function function arr_uintersect_Function ( $a , $b ) { if ( $a === $b ) { return 0; } return ( $a > $b )? eleven; }  
// List of two arrays with index and values ​​ $arr1 = array ( "a" = > "Java" , " b " = > "Program" , "c" = > "Practice" , "d" = > "in" , " f " = > "Geeksforengineer"); $arr2 = array ( "a" = > "Java" , "b" = > "Code" , "c " = > " write " , "d" = > "in" , "f" = > "GeeksforengineerIDE"); $result = array_uintersect_assoc ( $arr1 , $arr2 , "arr_uintersect_Function" );  
// Show result print_r ( $result );  
?>
Exit:
Array ([ a] = > Java [d] = > in)
Program 2:This program uses two arrays (array1 and array2) and a custom key comparison function (arr_uintersect_Function). If the arrays don`t match any key and values, it returns NULL.  
// PHP program for the array_uintersect_assoc() function 
// Custom function function arr_uintersect_Function ( $a , $b ) { if ( $a === $b ) { return 0; } return ( $a > $b )? eleven; }  
// List of two arrays with index and values ​​ $arr1 = array ( "a" = > "my" , " b " = > "best" , "c" = > "programming" , "d" = > "blog" , " e " = > "Geeksforengineer"); $arr2 = array ( "f" = > "My" , "g" = > "first" , "h " = > " programm " , "i" = > "Geeks Hello"); $arr3 = array ( "j" = > "Analysis" , "k" = > "Algorithm" , "l " = > " and " , "m" = > "Practice"); $result = array_uintersect_assoc ( $arr1 , $arr2 , $arr3 , "arr_uintersect_Function" );  
// Show result print_r ( $result );  
?>
Exit:
Array()
Program 3:This program returns all $arr1 values ​​that are present in all arguments. $arr1 = array ( " a " = > " gfg " , "b" = > "ide" , "c" = > "runcode"); $arr2 = array ( "a" = > "GFG" , "B" = > "practice"); $arr3 = array ( "a" = > "Gfg" , "B" = > "contribute"); print_r ( array_uintersect_assoc ( $arr1 , $arr2 , $arr3 , "strcasecmp" ));  
?>
Exit:
Array ([ a] = > gfg)
Link: https://www.php.net/manual/en/function.array-uintersect-assoc.php



Get Solution for free from DataCamp guru