1

i have array which has multiple duplicate values. now i want to get those duplicate values.

           $roQ = Array
           (
    [0] => 2123 
    [1] => 2094 
    [2] => 2105 
    [3] => 2160 
    [4] => 2143 
    [5] => 2148 
    [6] => 2154 
    [7] => 2155
    [8] => 2145
    [9] => 2123 
    [10] => 2149
     [11] => 2143 
     [12] => 2145

       )

i tried following code which is not working. it returns incorrect result. how to get the all duplicate values in new array.

   $c = array_count_values($roQ); 
       $val = array_search(max($c), $c);
      $azq[] = $val;
3

3 Answers 3

0

Try with -

$arr = array(1, 4, 6, 1, 8, 9, 4, 6);

$unique = array_unique($arr);

$duplicates = array_diff_assoc($arr, $unique);

var_dump($duplicates);
Sign up to request clarification or add additional context in comments.

Comments

0
$roQ = Array
           (
    [0] => 2123 
    [1] => 2094 
    [2] => 2105 
    [3] => 2160 
    [4] => 2143 
    [5] => 2148 
    [6] => 2154 
    [7] => 2155
    [8] => 2145
    [9] => 2123 
    [10] => 2149
     [11] => 2143 
     [12] => 2145

       )

for($i=0; $i<= count($roQ), $i++){

  if(!in_array($roQ[$i],$arr){

     $unique_value[] = $roQ[$i]; 

  }else {

     $dublicate_array[]=$roQ[$i]

  }

   array_push($arr, $req[$i]);

}

Comments

0

Try this code it displays the duplicate elements in an array.

$array = array(
            0 => 2123,
            1 => 2094,
            2 => 2105,
            3 => 2160,
            4 => 2143,
            5 => 2148,
            6 => 2154,
            7 => 2155,
            8 => 2145,
            9 => 2123,
            10 => 2149,
            11 => 2143,
            12 => 2145

        );
        $arrayNew = array_count_values($array);
        $finalArr = array ();
        $i=0;
        foreach ($arrayNew as $key => $Array_new){
            if($Array_new>1){

                 $finalArr[$i]  = $key;
                 $i++;
            }
       }
        echo "<pre>";
        print_r($finalArr);
        exit;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.