0

I would like to get all the duplicate values from an array, but all i see here is how to remove them, is there any way in retrieving only the duplicates and showing how many times they have duplicated?

For example

array(
  array(1,2,3,4,5,6),
  array(6,5,4,3,2,1),
  array(1,2,3,4,5,6),
  array(3,4,8,4,3,1),
  array(6,5,4,3,2,1),
)

I want to have like array(1,2,3,4,5,6) duplicated 2 times and array(6,5,4,3,2,1) also duplicated 2 times

Those that are not duplicated will be ignored.

1 Answer 1

1

Demo

foreach($array as $arr)
{
  $o[implode(',', $arr)][] = 1;
}
array_walk($o, function($v, $k){echo $k.':'.count($v);});
Sign up to request clarification or add additional context in comments.

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.