I am trying to find duplicated values/string in an array using `for` loop

```
    <?php
    $b=array('a','b','c','a','b');
    $c=count($b);
    $d=array();

    for($i=0;$i<=($c-1);$i++)
    {
        for($j=1;$j<=($c-1);$j++)
        {       

            if($b[$i]!=$b[$j])
            {       
             $flag=1;   
            }

        }

        if($flag==1)
        {
        $d[$i]=$b[$i];
        }

    }   

    print_R($d);
    ?>

```

where is my mistake? I have used array $d to display non duplicate values.....

**NOTE:** I need to try this **only** with `for` loop - I know how to do it using array functions.