array_unique
Removes duplicate values from an array and returns the array with unique values only.
Parameters
main.php
Return Values
array
Returns the filtered array with unique values
On success:Array with duplicate values removed, keys preserved
On failure:Original array if no duplicates found
Notes
- Preserves keys from the first occurrence of each value
- Use SORT_NUMERIC flag for numeric comparison
- Use SORT_REGULAR flag for normal comparison
- Keys are not reindexed - use array_values() if needed
Changelog
- 7.2.0: SORT_NUMERIC and SORT_STRING behavior aligned
Related Functions
array_filter
ArrayFilters elements of an array using a callback function, returning only elements that pass the test.
filtercallbackarray
uniqid
MiscGenerates a unique identifier based on the current time in microseconds.
uniqueidentifiersession
array_diff
ArrayCompares two or more arrays and returns the values from the first array that are not present in any of the other arrays.
comparedifferencefilter