Php Arrays Key & Values Comparison

What is array_diff_assoc Function?


The "array_diff_assoc" function is used to compute the difference of arrays Keys and Values and return the difference of arrays.



In the above syntax "array1" is the array to be compare with, "array2" is the array which is to be compared to, atleast two arrays should be there,"array 3" is optional.It returns all values of "array1" that is not present in any other array.

Example :

$a = array( 'x' => 'x','y' => 'y','g' => 'g');
$b = array( 'x' => 'x','y' => 'y',);
Result :

Array ([g] => g)

In the above example the two arrays "$a","$b" are compared, by default all values of the first array are taken, 'g' is the only value that is not in the array "$b", so its displayed as output.

PHP Topics

Ask Questions

Ask Question