Previous | Home | Next |
array_uintersect()()
The array_uintersect() function compares the values of two or more arrays, and returns the matches.
Syntax:array_uintersect(array1,array2,array3...,myfunction)
In above syntax, "array1" is the array to compare from, "array2" is an array to compare against, "array3,..." and more arrays to compare against and "myfunction" is a string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument
Example:
<?php function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"Apple","b"=>"Mango","c"=>"Orange"); $a2=array("a"=>"Orange","b"=>"Banana","e"=>"Orange"); $result=array_uintersect($a1,$a2,"myfunction"); print_r($result); ?>
Output:
array_uintersect_assoc()
The array_uintersect_assoc() function compares the keys and values of two or more arrays, and returns the matches.
Syntax:array_uintersect_assoc(array1,array2,array3...,myfunction)
In above syntax, "array1" is the array to compare from, "array2" is an array to compare against, "array3,..." and more arrays to compare against and "myfunction" is a string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument
Example:
<?php function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"Apple","b"=>"Mango","c"=>"Orange"); $a2=array("a"=>"Apple","b"=>"Orange","c"=>"Mango"); $result=array_uintersect_assoc($a1,$a2,"myfunction"); print_r($result); ?>
Output:
array_uintersect_uassoc()
The array_uintersect_uassoc() function compares the keys and values of two or more arrays, and returns the matches.
Syntax:array_uintersect_assoc(array1,array2,array3...,myfunction_key,myfunction_value)
In above syntax, "array1" is the array to compare from, "array2" is an array to compare against, "array3,..." and more arrays to compare against and "myfunction_key" is the name of the user-defined function that compares the array keys. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument and "myfunction_value" the name of the user-defined function that compares the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument
Example:
<?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"=>"Apple","b"=>"Mango","c"=>"Orange"); $a2=array("a"=>"Apple","b"=>"Mango","c"=>"Mango"); $result=array_uintersect_uassoc($a1,$a2,"myfunction_key","myfunction_value"); print_r($result); ?>
Output:
Previous | Home | Next |