How to remove duplicate value from the array using PHP?

How to remove duplicate value from the array using PHP?

  • 14 July, 2018
  • Renish Khunt
  • PHP
  • 49

Many time we get the array with contains the duplicate value. how we can find that duplicate value form array and remove it easily. we can remove duplicate value from the array using array_unique()¬†function of PHP. Let’s the example If our array look like.

 

$array = array(
    "a" => "First",
    "Second",
    "b" => "First",
    "Third",
    "Second",
    "Four"
);

$array = array_unique($array);
echo '<pre>'; 
print_r($array); 
exit;

The output after removing duplicate value form array is below

Array
(
 [a] => First
 [0] => Second
 [1] => Third
 [3] => Four
)

If you have any question write the comment below.