PHP array_intersect_uassoc() function

The array_intersect_uassoc () function in PHP is used to compute the intersection of arrays with the help of an additional index check, comparing indexes by a callable function. It returns an array containing all the entries from array1 that are present in all the other arrays.

Syntax

array_intersect_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 values in array1 that are present in all the other arrays.

Example 1

 "green", "b" => "brown", "i" => "indigo", "red");
//initializing the input array1
$array2 = array("g" => "GREEN", "b" => "brown", "yellow", "red");
//return the intersection of arrays
print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
?> 

Output

Array
(
[b] => brown
) 

Example 2

$b)?1:-1;
}

$array1=array("1"=>"red","2"=>"green","3"=>"blue");
$array2=array("1"=>"red","5"=>"green","9"=>"blue");
$array3=array("1"=>"red","4"=>"green","7"=>"red");
// comparing the keys and values with additional index check 
$intersection=array_intersect_uassoc ($array1,$array2,$array3,"myfunction");
//returns the intersection
print_r($intersection);
?> 

Output

Array
(
[1] => red
)

Example 3

 $b)? 1: 0; 
 } 
 // initializing the Input Array 1 
 $array1 = array(05=>"Reema", 10=>"raj", 30=>"Atul"); 
 // initializing the Input Array 2
 $array2 = array(05=>"Reema", 25=>"Reema", 30=>"Atul",70=>"Atul"); 
 // comparing the keys and values with additional index check  
 $intersection=array_intersect_uassoc($array1, $array2, "my_function"); 
 //returning the intersection
 print_r($intersection); 
 ?> 

Output

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


Related Topics

PHP unserialize() Function

PHP unserialize() Function The unserialize() function in PHP takes a single serialized variable and converts it back into a PHP value. Syntax unserialize ( string $str [, array $options ] ) Parameter value(required)- This parameter represents the serialized string. options(optional)- This parameter signifies any options to be...

1 minute read.

PHP array_push() Function

PHP array_push() Function The array_push() function in PHP pushes one or more elements onto the end of the array. This function increases the length of the array by the number of variables pushed. Syntax array_push ( array &$array, mixed& value [, mixed $... ]...

1 minute read.

PHP usort() Function

PHP usort() Function The usort() function in PHP sorts  array by values using a user-defined comparison function. Syntax usort ( array &$array , callable $value_compare_func ) array(required)- This parameter represents the input array. value_compare_func(required)- This parameter represents a string that describe a callable comparison function. The comparison...

1 minute read.

PHP Explode() Function

PHP Explode The PHP explode( ) is used to break a string into an array. The PHP explode( ) allow us to break a string into a smaller text with each break...

1 minute read.

WordPress Theme

Writing our WordPress Theme is relatively simple. Requirements: Before we begin, we need to know about the following set of requirements. We need to have full knowledge of WordPress setup, which is either...

2 minutes read.

PHP nl_langinfo() Function

PHP nl_langinfo() Function The nl_langinfo() function in PHP returns specific local information. This function does not work on Windows platforms. Syntax nl_langinfo ( int $item ) Parameter Item(required)- This parameter specifies the  integer value of the element or the constant name of the...

1 minute read.

PHP Environment Setup

To install PHP, We have to installed AMP(Apache, MySQL and PHP) software. There are various AMP software available in the market. XAMPP (Cross-Platform, Apache, MySQL, PHP and Perl) for windows. ...

2 minutes read.

PHP Comment

PHP commentis a line of code that is not executed. It is often used by developer to understand the code. PHP support single and multiple comments. In other language like C,...

1 minute read.

PHP String

PHP string is a sequence of characters. It is used to store and manipulate text. We can specify a string literal in four ways: single quoted double quoted heredoc syntax ...

2 minutes read.

PHP array_unshift() Function

PHP array_unshift() Function The array_unshift () function in PHP prepends one or more elements to the beginning or front of an array. It returns the new number of elements in the array. Syntax array_unshift ( array &$array [, mixed $... ] ) Parameter array(required)- This array represents...

1 minute read.

PHP array_multisort() Function

PHP array_multisort () Function The array_multisort() function in PHP sorts multiple or multi-dimensional arrays at once. Syntax array_multisort ( array &$array1 [, mixed $array1_sort_order [, mixed $array1_sort_flags [, mixed $... ]]] ) Parameter array1(required)- This parameter specified the input array to sort. array1_sort_order(optional)- This parameter specifies the order (ascending or descending)...

1 minute read.

PHP crypt() Function

PHP crypt() Function The crypt () function in PHP returns a hashed string using DES, Blowfish, or MD5 algorithms. Some constants of crypt() function are as follows: [CRYPT_STD_DES][CRYPT_EXT_DES][CRYPT_MD5][CRYPT_BLOWFISH][CRYPT_SHA_256][CRYPT_SHA_512] etc. Syntax crypt ( string $str [, string $salt ] )  Parameter str(required)- This parameter represents the string to be hashed salt(optional)- This parameter...

2 minutes read.

PHP key() Function

PHP key() Function The key() function in PHP fetches a key from an array and returns the index element of the current array position. Syntax key ( array $array ) Parameter array(required)- This parameter represents the input array. Return This function returns the key of the...

1 minute read.

PHP array_intersect_key() function

The array_intersect_key () function in PHP is used to compute the intersection of arrays using keys for comparison. It returns an array containing all the entries from array1 which have keys that are present in...

1 minute read.

PHP array_replace() Function

PHP array_replace() Function The array_replace() function in PHP replaces the elements from passed arrays into the first array with values having the same keys in each of the following arrays. Syntax array_replace ( array $array1 [, array $... ] ) Parameter array(required)- This parameter represents...

1 minute read.

PHP array_intersect_uassoc() function

The array_intersect_uassoc () function in PHP is used to compute the intersection of arrays with the help of an additional index check, comparing indexes by a callable function. It returns an array containing...

1 minute read.

PHP array_reverse() Function

PHP array_reverse() Function The array_reverse() function in PHP returns a new array with the elements in the reversed order. Syntax array_reverse (array $array [, bool $preserve_keys = FALSE ] ) Parameter array(required)- This parameter represents the input array preserve_keys (optional)- This parameter specifies if the function should preserve the keys...

1 minute read.

PHP convert_uudecode() Function

PHP convert_uudecode() Function The convert_uudecode() function in PHP decodes a uuencoded string. Syntax convert_uudecode ( string $data ) Parameter data- This parameter represents the uuencoded data. Return This function returns the decoded data as a string or FALSE on failure. Example 1 <?php // initializing the string $str...

1 minute read.

PHP printf() Function

PHP printf() Function The printf() function in PHP outputs a formatted string. The related functions of printf() function are as follows: sprintf()vprintf()vsprintf()fprintf()vfprintf() Syntax printf ( string $format [, mixed $... ] )  Parameter format(required)- This parameter formats the string which is composed of zero or...

1 minute read.

PHP Switch Statement with Example

PHP switch statement The PHP switch statement is used to execute one condition from many conditions.It similar to if statements on the same expression. Syntax: switch(n) {             case1: statement if n=case1; break;             case2:             statement if n=case2; break;             case3:            ...

3 minutes read.