PHP array_unique() Function
Definition
The array_unique()
returns the unique values with duplicate values removed.
Syntax
PHP array_unique() Function has the following syntax.
array array_unique ( array arr )
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to filter |
sortingtype | Optional. | How to compare the array elements/items. |
Possible values for sortingtype:
- SORT_STRING - Default. Compare items as strings
- SORT_REGULAR - Compare items normally (don't change types)
- SORT_NUMERIC - Compare items numerically
- SORT_LOCALE_STRING - Compare items as strings, based on current locale
Example
Returns the unique values with duplicate values removed
<?PHP/*from w ww .j ava2 s .com*/
$toppings2 = array("A", "B", "B", "C","java2s.com");
$toppings2 = array_unique($toppings2);
print_r($toppings2);
?>
The code above generates the following result.