Jump to content

not unique


Zugzwangle

Recommended Posts

I have tried the below:

$uniqueArr = array_diff($thisArray, array_unique($thisArray));
echo print_r($uniqueArr, true);  // returns "Array ( )"

 

I have tried to echo print_r, on the $uniqueArr, but it simply returns "Array ( )". There are definitely duplicates within $thisArray.  What am I doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/208379-not-unique/#findComment-1088942
Share on other sites

Arrgh... that's because array_unique doesn't do what we thought it was doing. It removes duplicates, not returns unique values.

 

<?php

$a1 = array('a','b','b','c','d','d');
$a2 = array_count_values($a1);
$a3 = array();
foreach($a2 as $key => $value) {
  if($value > 1) {
    $a3[] = $key;
  }
}

print_r($a3);

Link to comment
https://forums.phpfreaks.com/topic/208379-not-unique/#findComment-1088947
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.