How to remove all instances of duplicated values from an array

前端 未结 9 1089
心在旅途
心在旅途 2021-01-02 19:48

I know there is array_unique function, but I want to remove duplicates. Is there a built-in function or do I have to roll my own.

Example input:

9条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 20:14

    You can use a combination of array_unique, array_diff_assoc and array_diff:

    array_diff($arr, array_diff_assoc($arr, array_unique($arr)))
    

提交回复
热议问题