difference between two arrays
Solution 1:
To get the difference between the two arrays you need to do the following:
$fullDiff = array_merge(array_diff($array1, $array2), array_diff($array2, $array1));
The reason being that array_diff()
will only give you the values that are in $array1
but not $array2
, not the other way around. The above will give you both.
Solution 2:
Note: this answer will return the values in $array2
that are not present in $array1
, it will not return the values in $array1
that are not in $array2
.
$diff = array_diff($array2, $array1);
array_diff()