PHP array_diff_uassoc() Function

PHP array_diff_uassoc() Function

The array_diff_uassoc () Function in PHP is used to compare the keys and values of two (or more) arrays and returns the differences (an array containing the entries from the first array that are not present in any of the other arrays).

This function computes the difference of arrays with additional index check which is performed by callback function.

Syntax

array_diff_uassoc (array $array1, array $array2 [, array $...], callable $key_compare_func )

Parameter

array1(required)- This parameter signifies the input array to compare from.

array2(required)- This parameter signifies the input array to compare against.

array3….(optional)- It represents more arrays to compare against

key_compare_func(required)- This parameter represents a string that describe a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Return

This function returns an array containing all the entries from array1 that are not present in any of the other arrays.

Example 1

$b)?1:-1; 
 }
 $array1=array("1"=>"red","2"=>"green","3"=>"blue");
 $array2=array("1"=>"red","5"=>"green","9"=>"blue");
 $array3=array("3"=>"yellow","4"=>"red","7"=>"blue");
 // comparing the keys and values with additional index check 
 $difference=array_diff_uassoc($array1,$array2,$array3,"myfunction"); 
 print_r($difference);
 ?> 

Output

Array
 (
     [2] => green
     [3] => blue
 ) 

Example 2

$b)? 1: 0; 
 } 
 // initializing the Input Array 1 
 $array1 = array(05=>"Reema", 10=>"raj", 30=>"Atul"); 
 // initializing the Input Array 2
 $array2 = array(20=>"Mahesh", 40=>"Smitha", 30=>"Ritu");  
 // comparing the keys and values with additional index check  
 $difference=array_diff_uassoc($array1, $array2, "my_function"); 
 print_r($difference); 
 ?> 

Output

Array
 (
     [5] => Reema
     [10] => raj
     [30] => Atul
 )