How to remove duplicate value from the array using PHP?

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s