You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== array_unique ==
Copy Code
The output would be:
Copy Code
The output would be:
Copy Code
The output would be:
Removes all non-unique values from an array.
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| array_unique
|-
! scope="row" | Returns
| array
|-
! scope="row" | Usages
| array, [compareTypes]
|-
! scope="row" | Throws
| [[../objects/ms.lang.CastException|ms.lang.CastException]]
|-
! scope="row" | Since
| 3.3.1
|-
! scope="row" | Restricted
| No
|-
! scope="row" | Optimizations
| [[../../Optimizer#NO_SIDE_EFFECTS|NO_SIDE_EFFECTS]]
|}compareTypes is true by default, which means that in the array array(1, '1'), nothing would be removed from the array, since both values are different data types. However, if compareTypes is false, then the first value would remain, but the second value would be removed. A new array is returned. If the array is associative, by definition, there are no unique values, so a clone of the array is returned.
=== Usages ===
array_unique(array, [compareTypes])=== Examples === ====Example 1==== Basic usage Given the following code:
array_unique(array(1, 2, 2, 3, 4))

1 {{function|array_unique}}({{function|array}}(1, 2, 2, 3, 4))
:{1, 2, 3, 4}====Example 2==== No removal of different datatypes Given the following code:
array_unique(array(1, '1'))

1 {{function|array_unique}}({{function|array}}(1, '1'))
:{1, 1}====Example 3==== Removal of different datatypes, by setting compareTypes to false Given the following code:
array_unique(array(1, '1'), false)

1 {{function|array_unique}}({{function|array}}(1, '1'), {{keyword|false}})
:{1}
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)