开发者

How to check whether a non-assoc array is unique in PHP?

I wan开发者_如何学Got to know whether the array $arr has duplicate elements.


array_unique() should work:

if (count(array_unique($arr)) == count($arr)) 
  echo "Array does not contain duplicate elements"; 
else
  echo "Array contains duplicate elements";


Check out array_unique.


I'm not sure there is a built in function for that. But you could do

if (count($arr) == count(array_unique($arr))
{
    //array has no unique elements
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜