Current Location: Home> Function Categories> array_udiff_assoc

array_udiff_assoc

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

Definition and usage

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

Note: This function uses built-in functions to compare key names, and uses user-defined functions to compare 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 (using built-in functions to compare key names, using user-defined functions to compare key values), and return the difference:

 <?php
function myfunction ( $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" => "blue" , ​​"c" => "green" ) ;

$result = array_udiff_assoc ( $a1 , $a2 , "myfunction" ) ;
print_r ( $result ) ;
?>

Try it yourself

Similar Functions
Popular Articles