diff --git a/reference/array/functions/array-diff.xml b/reference/array/functions/array-diff.xml index 4b691cf60c..ce5563efc8 100644 --- a/reference/array/functions/array-diff.xml +++ b/reference/array/functions/array-diff.xml @@ -58,6 +58,7 @@ Returns an array containing all the entries from array1 that are not present in any of the other arrays. + Keys in the array1 array are preserved. @@ -91,18 +92,54 @@ Array + + + + <function>array_diff</function> 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; - - - Two elements are considered equal if and only if - (string) $elem1 === (string) $elem2. In other words: - when the string representation is the same. - - - This function only checks one dimension of a n-dimensional @@ -117,6 +154,7 @@ Array array_diff_assoc + array_udiff array_intersect array_intersect_assoc