array_diff in PHP

Syntax of array_diff

array array_diff(array array1, array array2[, … array arrayN])

Returns an array that contains all of the values from the first array that are not present in any of the other provided arrays. The keys of the values are preserved

Example of array_diff

$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);

    [1] => blue

Leave a Comment