Check and return duplicates array php

前端 未结 10 2112
我寻月下人不归
我寻月下人不归 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:30

    You can get the difference of the original array and a copy without duplicates using array_unique and array_diff_assoc:

    array_diff_assoc($arr, array_unique($arr))
    

提交回复
热议问题