To remove duplicate values from an array using PHP, we have to use the PHP array_unique() function. It removes duplicate values or elements from the array. If our array contains string keys, then this function will keep the first encountered key for every value and will ignore all other subsequent keys.

Example

                                        

$var = array("a"=>"best","b"=>"interview","c"=>"question","d"=>"interview");

print_r(array_unique($var));

OUTPUT

Array ( [a] => best [b] => interview [c] => question)

Suggest An Answer

No suggestions Available!