The array_udiff_uassoc() Function is an inbuilt function in PHP and is used for distinguishing between two or more array. The function computes the differences array by use of two user-defined functions with the additional index key. It compares both data and index by use of callback functions and returns the difference.
array_udiff_uassoc($arr1, $arr2, $arr3........nth array, value_Funtion, key_Funtion )
Parameters Used: This array_udiff_uassoc() function parameters are described below:
- $arr1, $arr2, $arr3, $arr4,…., $arrn : This represents the list of arrays which we want to distinguish.
- value_Funtion: This parameter repesents the user-defined function. This user defined function will be used to compare values.
- key_Funtion: It is also a user-defined function. This user-defined function is used to compares arrays keys.
Note: Both comparison functions (value_Funtion, key_Funtion) returns an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.
Return Value: This function returns an array containing all values of the array $arr1 which are not present in any other arrays.
Some related functions:
- PHP | arr_diff() Function : Compute differences of an array.
- PHP | arr_udiff() Function: Compute differences of an array by used user-defined callback function and compare data.
- PHP | array_diff_assoc() Function : Compute differences of an array with additional index key.
- PHP | array_diff_uassoc() Function: This function compares both the keys and values between one or more arrays to and returns the elements from the first array which are not there in the rest of arrays.
- PHP | array_diff_key() Function: Compares the key of the first array of parameters with rest of the arrays and returns an array containing all the entries from $array1 that are not present in any of the other arrays.
Below programs illustrate the array_udiff_uassoc() Function.
Array ( [n] => Java lab [o] => C# lab [y] => Ruby lab )
Array ( [e] => Ruby lab )
Array ( )
Program: 4 Take three array (array1 and array2, array3) and using comparison function array_udiff_uassoc() Function. Where all three array has same index but values are different then return first array.
Array ( [a] => C lab [b] => Java lab [d] => C# lab )
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.