PHP array_unique() Function
In this chapter you will learn:
- Definition for PHP array_unique() Function
- Syntax for PHP array_unique() Function
- Parameter for PHP array_unique() Function
- Example - returns the unique values with duplicate values removed
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// j a va2s. c o m
$toppings2 = array("A", "B", "B", "C","java2s.com");
$toppings2 = array_unique($toppings2);
print_r($toppings2);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP array_unshift() Function
- Syntax for PHP array_unshift() Function
- Parameter for PHP array_unshift() Function
- Note for PHP array_unshift() Function
- Note 2 for PHP array_unshift() Function
- Example - adds a value onto the start of the array
- Example - Adds two value onto the start of the array
Home » PHP Tutorial » PHP Array Functions