Remove duplicate values from an array in PHP

Solution: Use the PHP array_unique() function

You can use the PHP array_unique() function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed.

$arr = array("green", "red", "green", "yellow", "red");

// Deleting the duplicate items
$result = array_unique($arr);

    [0] => green
    [1] => red
    [3] => yellow
Leave a reply
Captcha Click on image to update the captcha .