The array_unique() function removes duplicate values from an array. It returns the filtered array with unique elements.
Syntax
array_unique(arr, compare)
Parameters
arr − The specified array.
compare − Specifies how to compare the array elements/items. Possible values
SORT_STRING − Compare items as strings
SORT_REGULAR − Compare items without changing types
SORT_NUMERIC − Compare items numerically
SORT_LOCALE_STRING − Compare items as strings, based on current local.
Return
The array_unique() function returns the filtered array.
Example
The following is an example −
<?php $arr = array("a"=>"one","b"=>"two","c"=>"two", "d"=>"three", "e"=>"three"); print_r(array_unique($arr)); ?>
Output
Array ( [a] => one [b] => two [d] => three )