Current Location: Home> Function Categories> array_udiff_uassoc

array_udiff_uassoc

Calculate the difference set of arrays with index checks, and use callback functions to compare data and indexes
Name:array_udiff_uassoc
Category:Array
Programming Language:php
One-line Description:Compare arrays, return the difference set (compare keys and values, using two user-defined key names comparison functions).

Definition and usage

The array_udiff_uassoc() function is used to compare the key names and key values ​​of two (or more) arrays and return the difference set.

Note: This function is compared using two user-defined functions; the first function compares the key names, and the second function compares the key values!

The function compares the key names and key values ​​of two (or more) arrays and returns an array of differences that include all key names and key values ​​in the array being compared ( array1 ) but not in any other parameter array ( array2 or array3 , etc.).

Example

Compare the key names and key values ​​of two arrays (compare with user-defined functions) and return the difference:

 <?php
function myfunction_key ( $a , $b )
{
if ( $a === $b )
  {
  return 0 ;
  }
  return ( $a > $b ) ? 1 : - 1 ;
}

function myfunction_value ( $a , $b )
{
if ( $a === $b )
  {
  return 0 ;
  }
  return ( $a > $b ) ? 1 : - 1 ;
}

$a1 = array ( "a" => "red" , "b" => "green" , "c" => "blue" ) ;
$a2 = array ( "a" => "red" , "b" => "green" , "c" => "green" ) ;

$result = array_udiff_uassoc ( $a1 , $a2 , "myfunction_key" , "myfunction_value" ) ;
print_r ( $result ) ;
?>

Try it yourself

Similar Functions
Popular Articles