Current Location: Home> Function Categories> array_uintersect_assoc

array_uintersect_assoc

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

Definition and usage

The array_uintersect_assoc() function is used to compare the key names and key values ​​of two (or more) arrays and returns the intersection (match).

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 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. Data (key value) are compared using callback functions.

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 intersection:

 <?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_uintersect_assoc ( $a1 , $a2 , "myfunction" ) ;
print_r ( $result ) ;
?>

Try it yourself

Similar Functions
Popular Articles