English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_unique() function is used to remove duplicate values from an array
array_unique($array);
The array_unique() function removes duplicate values from an array. Note that the key names are retained unchanged. array_unique() first sorts the values as strings, then retains the first encountered key name for each value, and then ignores all subsequent key names. This does not mean that the first occurrence of the same value in the unsorted array will retain the key name.
Serial Number | Parameters and Description |
---|---|
1 | array1(Required) It specifies an array. |
Accepts an array as input and returns a new array without duplicate values.
Use array_unique to remove duplicate element values from a specified array
<?php $input = array("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique($input); print_r($result); ?>Test and See‹/›
Output Result:
Array ( [a] => green [0] => red [1] => blue )