How can we remove duplicate value from an array in php?

207 Views

How can we remove duplicate value from an array in php?

Duplicate value can remove from an array by using array_unique function. If two or more array values are the same, the first appearance will be kept and the other will be removed. It takes an input array and returns a new array without duplicate values.

array_unique(array)
 
 
<?php

	$a=array("a"=>"red","b"=>"blue","c"=>"green", "d"=>"red");

	print_r(array_unique($a));

?>

// output

Array ( 
    [a] => red 
    [b] => blue
    [c] => green 
    )

 

Tags:-
PHP