Check and return duplicates array php

前端 未结 10 2111
我寻月下人不归
我寻月下人不归 2020-12-05 22:33

I would like to check if my array has any duplicates and return the duplicated values in an array. I want this to be as efficient as possible.

Example:



        
10条回答
  •  [愿得一人]
    2020-12-05 23:14

    this will be ~100 times faster than array_diff

    $dups = array();
    foreach(array_count_values($arr) as $val => $c)
        if($c > 1) $dups[] = $val;
    

提交回复
热议问题