array_diff
Compares two or more arrays and returns the values from the first array that are not present in any of the other arrays.
Parameters
main.php
Return Values
array
Returns an array containing all entries from array1 that are not present in any other arrays
On success:Array with values from first array not found in other arrays, preserving original keys
On failure:Empty array if no differences found or first array is empty
Notes
- Comparison is done using string comparison, so values are cast to strings
- Keys from the first array are preserved in the result
- Only compares values, not keys - use array_diff_key() for key comparison
- Use strict comparison with array_udiff() if needed for custom comparison
Changelog
- 4.0.1: Function was introduced
- 5.0.0: Now supports unlimited number of arrays for comparison
Related Functions
array_filter
ArrayFilters elements of an array using a callback function, returning only elements that pass the test.
filtercallbackarray
array_unique
ArrayRemoves duplicate values from an array and returns the array with unique values only.
uniquededuplicatefilter
usort
ArraySorts an array by values using a user-defined comparison function, losing original keys.
sortcustomcompare
max
MathReturns the highest value among the given values, or the highest value in an array.
maximumcomparehighest
min
MathReturns the lowest value among the given values, or the lowest value in an array.
minimumcomparelowest