Question: I was just going through these questions for PHP and got stuck at one of them. The question is:

> 
> You have a PHP 1 dimensional array. Please write a PHP function that
> takes 1 array as its parameter and returns an array. The function must
> delete values in the input array that shows up 3 times or more?
> 
> 
> For example, if you give the function
> 
> 
> array(1, 3, 5, 2, 6, 6, 6, 3, 1, 9)`the function will return`array(1, 3, 5, 2, 3, 1, 9)
> 
> 
> 

I was able to check if they are repeating themselves but I apply it to the array I am getting as input.

```
function removeDuplicate($array){
    $result = array_count_values( $array );
    $values = implode(" ",  array_values($result));
    echo $values . "<br>";  
}

$qArray = array(1, 3, 5, 2, 6, 6, 6, 3, 1, 9);
removeDuplicate($qArray);

```

One more thing, we cannot use `array_unique` because it includes the value which is repeated and in question we totally remove them from the current array.

Answer: 
You can use this function with any number of occurrences you want - by default 3

```
function removeDuplicate($arr, $x = 3){
    $new = $rem = array();
    foreach($arr as $val) {
        $new[$val]++;
        if($new[$val]>=$x){
            $rem[$val]=$new[$val];
        }
    }
    $new = array_keys(array_diff_key($new, $rem));
    return $new;
}

```
You should use array\_unique funciton.

```
<?php
    $q = array(1, 3, 5, 2, 6, 6, 6, 3, 1, 9);
    print_r(array_unique($q));
?>

```

Try it and let me know if it worked.