Current Location: Home> Function Categories> array_uintersect_uassoc

array_uintersect_uassoc

Compute the intersection of arrays with index check, and use a separate callback function to compare data and indexes
Name:array_uintersect_uassoc
Category:Array
Programming Language:php
One-line Description:Compare arrays, return intersections (compare keys and values, using two user-defined key names comparison functions).

Definition and usage

array_uintersect_uassoc() function compares the key names and key values ​​of two (or more) arrays and returns the intersection.

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 intersection array that includes all key names and key values ​​in the array being compared ( array1 ) and also in any other parameter array ( array2 or array3 , etc.).

Note that the difference from array_uintersect() is that the key names should also be compared. Key values ​​and key names (indexes) are compared using callback functions.

Example

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

 <?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_uintersect_uassoc ( $a1 , $a2 , "myfunction_key" , "myfunction_value" ) ;
print_r ( $result ) ;
?>

Try it yourself

Similar Functions
Popular Articles