php: check if an array has duplicates

前端 未结 15 2368
情深已故
情深已故 2020-11-27 04:07

I\'m sure this is an extremely obvious question, and that there\'s a function that does exactly this, but I can\'t seem to find it. In PHP, I\'d like to know if my array has

15条回答
  •  粉色の甜心
    2020-11-27 05:06

    As you specifically said you didn't want to use array_unique I'm going to ignore the other answers despite the fact they're probably better.

    Why don't you use array_count_values() and then check if the resulting array has any value greater than 1?

提交回复
热议问题