![]() |
VOOZH | about |
The PHP array_unique() function removes duplicate values from an array, preserving the first occurrence of each value and reindexing the array with keys preserved. It's useful for filtering out redundant data and ensuring a collection of unique elements within an array.
array array_unique($array , $sort_flags)
Note: The keys of the array are preserved. That is, the keys of the not-removed elements of the input array will be the same in the output array.
Parameters
: This function accepts two parameters out of which one is mandatory and the other is optional. Both of these parameters are described below:
Return Value: The array_unique() function returns the filtered array after removing all duplicates from the array.
Below programs illustrate the array_unique() function in PHP:
Example : In this example we removes duplicate values from the array a using array_unique() and prints the result.
Array ( [0] => red [1] => green [3] => blue )
Example 2: In this example we removes duplicate values from the associative array arr using array_unique() and prints the result.
Array ( [a] => MH [b] => JK [d] => OR )