Home > Backend Development > PHP Tutorial > php-Arrays function-array_diff_uassoc-use callback function to do index check to calculate the difference of array_PHP tutorial

php-Arrays function-array_diff_uassoc-use callback function to do index check to calculate the difference of array_PHP tutorial

WBOY
Release: 2016-07-13 17:51:21
Original
1079 people have browsed it

array_diff_uassoc() function uses the callback function to do index checking to calculate the difference set of the array

【Function】
This function will return an array,
This array contains all values ​​in array1 that are not in any other parameter array.
If the first parameter is considered to be less than, equal to, or greater than the second parameter,
must be returned            An integer less than zero, equal to zero, or greater than zero
【Scope of use】
​​​​​ php5 (I tested this function with 5.1.6, and it is incorrect. 5.3.3 is correct, and the specific versions that work well need to be verified)
【Use】
array array_diff_uassoc( array array1, array array2[,array...,callback key_compare_func] )
           array1/required/array1
           array2/required/comparable array must have at least one
           array.../optional/array used for comparison
             key_compare_func.../Required/Provide users with a callback function as a comparison standard
【Example】
[php]
function myfunction($v1,$v2) { if ($v1===$v2) { return 0;
} if ($v1>$v2) { return 1;
} else { return -1;
} } $a1=array(0=>"Dog",1=>"Cat",2=>"Horse");
$a2=array(3=>"Dog",1=>"Cat",5=>"Horse");
print_r(array_diff_uassoc($a1,$a2,"myfunction"));
?>
Array ( [0] => Dog [2] => Horse )


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478201.htmlTechArticlearray_diff_uassoc() function uses the callback function to do index checking to calculate the difference set of the array [Function] This function will return a Array, this array contains everything in array1 but not in other...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template