Home How To Find Duplicate Values in Array PHP

How To Find Duplicate Values in Array PHP

34 viewsPHP
1

Most of the inbuilt function is available in PHP, who help us to solve the many problems but sometimes, they do not provide exact function who help us to solve the problem, but we can use some inbuilt function and can solve out, so here we will know How To Find Duplicate Values in Array PHP,  we will use array_count_values() PHP function and will get duplicate values in array.

How To Find Duplicate Values in Array PHP?

Let’s consider a simple array list and will find out duplicate values in the array.

<?php

$array = array(1,3,4,6,7,1);

$out = array_count_values($array);

foreach ($out as $key=>$value) {
    
    if ($value >1) {
        echo $key;
    }
}

Output

1
Changed status to publish