PHP array_uintersect_assoc() Function

PHP array_uintersect_assoc() Function

The array_uintersect_uassoc() function in PHP calculates the intersection of arrays by comparing the data and indexes by separate callback functions. It returns an array containing all the values of the first input array that are present in all the other given arrays.

Syntax

array_uintersect_uassoc ( array $array1 , array $array2 [, array $... ], callable $value_compare_func , callable $key_compare_func )

Parameter

array1(required)- This array represents the first input array.

array2(required)- This array represents the second input array.

array3….(optional)- It represents more arrays to compare against.

value_compare_func(required)- This parameter represents a string that describe a callable comparison function. The comparison function returns an integer greater (<), equal to (=), or less than ( >) than 0 if the first argument is greater(<), equal to(=), or less than( >) than the second argument.

key_compare_func(required)- This parameter represents the key comparison callback function.

Return

This function returns an array containing all the values of the first input array that are present in all the other given arrays.

Example 1

 "Reema", "b" => "bEENA", "c" => "Babita", "Ria");
 echo("Array 1:\n");
 print_r($array1);
 //initializing the input array2
 $array2 = array("a" => "REEMA", "b" => "beena", "Rahul", "Ria"); 
 echo("\nArray 2:\n");
 print_r($array2);
 //Computing the intersection of arrays with key and value functions
 $uintersect_uassoc=array_uintersect_uassoc($array1, $array2, "strcasecmp", "strcasecmp");
 echo("Intersection Array:\n");
 print_r($uintersect_uassoc);
 ?> 

Output

Array 1:
 Array
 (
     [a] => Reema
     [b] => bEENA
     [c] => Babita
     [0] => Ria
 ) 
 Array 2:
 Array
 (
     [a] => REEMA
     [b] => beena
     [0] => Rahul
     [1] => Ria 
 )
 Intersection Array:
 Array
 (
     [a] => Reema
     [b] => bEENA
 ) 

Example 2

$val2)?1:-1; 
 }
 //input array1
 $array1=array("a"=>"PHP","b"=>"C#","c"=>"C++","d"=>"Python","e"=>"AI");
 //input array2
 $array2=array("a"=>"PHP","b"=>"C#","c"=>"Python");
 //input array2
 $array3=array("a"=>"PHP","c"=>"Java","d"=>"AI","e"=>"C++");
 // returns the intersection of the three given arrays with the help of callable functions 
 $intersection_uassoc=array_uintersect_uassoc($array1,$array2,$array3,"myfunction","myfunction");
 //will return PHP
 print_r($intersection_uassoc);
 ?> 

Output

Array
 (
     [a] => PHP
 ) 

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", 40=>"Smitha", 30=>"Atul");  
 //returns the intersection of the three given arrays with the help of value callable functions
 $intersection=array_uintersect_uassoc ($array1, $array2, "myfunction","myfunction"); 
 //will return intersection Atul
 print_r($intersection); 
 ?> 

Output

Array
 (
     [30] => Atul
 ) 

Related Topics

PHP array_chunk() Function

PHP array_chunk() Function The array_chunk() function in PHP is used to split an array into chunks where the last chunk may contain less than size elements. Syntax array_chunk ( array $array , int $size [, bool $preserve_keys ]...

1 minute read.

PHP Validation

PHP validation is used to check whether the field is filled or not in the proper way by the user. There are two types of validation in PHP. Client Side Validation:...

5 minutes read.

PHP empty() Function

PHP empty() Function The empty() function in PHP determines whether the specified variable is empty or not. The specified variable is considered empty if it does not exist or if its value is equal to FALSE. This function...

1 minute read.

PHP ucwords() Function

PHP ucwords() Function The ucwords() function in PHP converts the first character of each word in the specified string to uppercase. It is a binary-safe function. The related function are as follows: ucfirst()lcfirst()strtoupper()strtolower() Syntax ucwords ( string $str [, string $delimiters ] ) Parameter str(required)- This parameter represents...

1 minute read.

PHP range() Function

PHP range() Function The range () function in PHP is used to create an array containing a range of elements. Syntax range ( mixed $start , mixed $end [, number $step = 1 ] ) Parameter start(required)- This parameter represents the first value of the sequence. end(required)- This parameter represents the...

1 minute read.

PHP strstr() Function

PHP strstr() Function The strstr() function in PHP finds the first occurrence of a string. It returns part of the parameter haystack string starting from and including the first occurrence of needle to the end of the haystack parameter. This function is case-sensitive.  Syntax strstr ( string $haystack , mixed $needle [, bool $before_needle] )  Parameter  haystack(required)-...

2 minutes read.

PHP doubleval() Function

PHP doubleval() Function The doubleval() function in PHP is used to give the float value of a variable. This function is an alias of floatval(). Syntax doubleval ( mixed $var ) Parameter var(required)- This parameter represents the name of the variable that...

1 minute read.

PHP money_format() Function

PHP money_format() Function The money_format() function in PHP formats a number as a currency string and returns a formatted version of number. Syntax money_format ( string $format , float $number )  Parameter format(required)- This parameter specifies the string to be formatted and how to format the...

1 minute read.

PHP key_exists() Function

PHP key_exists() Function The key_exists() function in PHP checks if the specified key or index exists in the array or not. Syntax key_exists ( mixed $key , array $array )  Parameter key(required)- This parameter represents the value to check. array(required)- This parameter signifies an input array with...

1 minute read.

PHP strval() function

PHP strval() function The strval() function in PHP is used to get the string value for the specified variable. This function cannot be used on arrays or objects, if applied then would return only the...

1 minute read.

PHP Variables

PHP Variable is the name of memory location used to hold the data.  In PHP, variable starts with $ symbol. Rules for PHP Variables. Variable starts with $ sign. Variable name...

2 minutes read.

PHP boolval() Function

PHP boolval() Function The boolval() function in PHP is used to give the Boolean value for a given variable. Syntax boolval ( mixed $var ) Parameter var(required)- This parameter represents the value that is converted to a boolean. It can be a...

1 minute read.

PHP array_map() Function

PHP array_map() Function The array_map() function  in PHP is used to return an array containing the results of applying the user-defined callback function over the elements of one or more arrays. Syntax array_map ( callable $callback , array $array1 [, array $... ] )  Parameter callable(required)- This parameter...

1 minute read.

PHP htmlspecialchars() Function

PHP htmlspecialchars() Function The htmlspecialchars() function in PHP converts some special predefined characters to HTML entities. The special predefined characters are as follows: & (ampersand) OR &amp;" (double quote) OR &quot;' (single quote) OR &#039;<...

2 minutes read.

PHP is_null() Function

The is_null() function in PHP is used to  find whether the specified variable is a null or not. It returns a Boolean value true if the parameter var is null else it returns...

1 minute read.

PHP strcasecmp() Function

PHP strcasecmp() Function The strcasecmp() function in PHP compares two strings. It is a binary-safe case-insensitive string function. Syntax strcasecmp ( string $str1 , string $str2 ) Parameter str1(required)- This parameter represents the first string. str2(required)- This parameter represents the second string. Return This function returns a value less than( <...

1 minute read.

PHP is_scalar() Function

PHP is_scalar() Function The is_scalar() function in PHP finds whether a variable is a scalar or not. It returns a Boolean value TRUE if the parameter var is scalar, else it returns FALSE. Scalar variables are those containing an integer, float, string or boolean. This...

1 minute read.

PHP natcasesort() Function

PHP natcasesort() Function The natcasesort() function in PHP Sort an array using a case insensitive "natural order" algorithm while maintaining the keys. Syntax natcasesort ( array &$array ) Parameter array(required)- This parameter represents the input array. Return This parameter returns a Boolean...

1 minute read.

PHP stripcslashes() Function

PHP stripcslashes() Function The stripcslashes() function in PHP returns a string with backslashes(\n, \r ..., octal and hexadecimal representation) stripped off. Syntax stripcslashes ( string $str )  Parameter str(required)- This parameter signifies the string to be unescaped. Return This function returns the unescaped string with backslashes stripped off. Example 1   ...

1 minute read.

PHP crc32() Function

PHP crc32() Function The crc32() function in PHP  Calculates the crc32 polynomial of a string. Syntax crc32( string $str ) Parameter str(required)- This parameter represents The string to be calculated Return This function returns the crc32 checksum of string as an integer. Example 1 ...

1 minute read.