array_diff()
array_diff() is a PHP native function that computes the difference between arrays, comparing values, using their string representation.
array_diff() takes an array $array, and one or several other arrays ...$arrays. It returns a new array made of the elements of $array whose value is not present in any of the other arrays, keeping the original keys of $array.
Values are compared as strings, so array_diff() may report false positives when comparing objects, arrays, or values with mixed types that share the same string representation.
There are several variants of this function: array_diff_key() compares the keys, instead of the values. array_diff_assoc() compares both keys and values. array_udiff() accepts a custom comparison callback for the values.
The complement function is array_intersect(), which returns the elements that are shared amongst the arrays.
<?php
$array1 = ['a' => 'green', 'b' => 'brown', 'c' => 'blue', 'red'];
$array2 = ['a' => 'green', 'yellow', 'red'];
$result = array_diff($array1, $array2);
print_r($result);
// ['b' => 'brown', 'c' => 'blue']
?>