array_diffComputes the difference of arrays
&reftitle.description;
arrayarray_diffarrayarrayarrayarrays
Compares array against one or more other arrays and
returns the values in array that are not present in
any of the other arrays.
&reftitle.parameters;
array
The array to compare from
arrays
Arrays to compare against
&reftitle.returnvalues;
Returns an array containing all the entries from
array that are not present in any of the other arrays.
Keys in the array array are preserved.
&reftitle.examples;
array_diff example
"green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
print_r($result);
?>
]]>
Multiple occurrences in $array1 are all
treated the same way. This will output :
blue
)
]]>
array_diff example with non-matching types
Two elements are considered equal if and only if
(string) $elem1 === (string) $elem2. That is,
when the string representation is the same.
v = $v;
}
public function __toString() {
return $this->v;
}
}
$source = [new S('a'), new S('b'), new S('c')];
$filter = [new S('b'), new S('c'), new S('d')];
$result = array_diff($source, $filter);
// $result now contains one instance of S('a');
?>
]]>
To use an alternate comparison function, see array_udiff.
&reftitle.notes;
This function only checks one dimension of a n-dimensional
array. Of course you can check deeper dimensions by using
array_diff($array1[0], $array2[0]);.
&reftitle.seealso;
array_diff_assocarray_udiffarray_intersectarray_intersect_assoc