array_unique — Removes duplicate values from an array

array_unique — Removes duplicate values from an array
Description

array array_unique ( array array )

array_unique() takes input array and returns a new array without duplicate values.

array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.[indent]Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

 

Example

	<?php
	$input = array(4, "4", "3", 4, 3, "3");
	$result = array_unique($input);
	var_dump($result);
	?>

Output

array(2) {
[0] => int(4)
[2] => string(1) "3"
}
<?php
$array = Array('A','B','C','D','B');
print_r($array); // Array ( [0] => A [1] => B [2] => C [3] => D [4] => B )
$result = array_unique($array);
print_r($result); // Array ( [0] => A [1] => B [2] => C [3] => D ) 
?>