Javatpoint Logo
Javatpoint Logo

PHP array_unique( ) function

The array_unique( ) function is an inbuilt function of PHP and it is used to remove duplicate values from an array. This function was introduced in 4.0.1

Syntax

Parameters

Parameter Description Is compulsory
array1 The input array. compulsory
sort_flags The optional second parameter sort_flags may be used to modify the sorting behavior using these values:
Sorting type flags
SORT_REGULAR - match items normally
SORT_NUMERIC - match items numerically
SORT_STRING - match items as strings
SORT_LOCALE_STRING - match items as strings, based on the current locale.
Optional

Return

The array_unique( ) function returns the filtered array.

Example 1

Output:

Array
(
    [a] => zee
    [c] =>aajtak
    [d] =>ndtv
)

Example 2

Output:

Array
(
    [0] => java
    [1] =>php
    [3] => python
    [4] => html
)

Example 3

Output:

Array
(
    [a] =>abhijeet
    [b] =>arijit
)

Example 4

Output:

Array
(
    [a] => dell
    [0] =>hp
    [1] =>leneovo
)





Help Others, Please Share

facebook twitter pinterest