Home >Backend Development >PHP Tutorial >php-Arrays function-array_diff_assoc-calculates the difference of arrays with index check_PHP tutorial
array_diff_assoc() function calculates the difference set of arrays with index check
【Function】
This function will return an array,
This array contains all values in array1 that are not in any other parameter array.
【Scope of use】
>=4.3.0, php5
【Use】
array array_diff_assoc( array array1, array array2[,array...] )
array1/required/array1
array2/required/comparable array must have at least one
array.../optional/array used for comparison
【Example】
[php]
$arr1 = array( "key1" => "val1", "key2" => "val2" );
$arr2 = array( "key1" => "val1", "key3" => "val2" );
$arr3 = array( "key2" => "val2" );
print_r( array_diff_assoc( $arr1, $arr2 ) );
print_r( array_diff_assoc( $arr1, $arr3 ) );
print_r( array_diff_assoc( $arr1, $arr2, $arr3 ) );
/*
Array
(
[key2] => val2
)
Array
(
[key1] => val1
)
Array
(
)
*/
Excerpted from zuodefeng’s notes