Page 1 of 1

[SOLVED] array function

Posted: Thu Apr 07, 2005 10:16 am
by dannymc1983
does anyone know of a way to find out if a number appears in an array more than once, is there an array function which will do this? for instance if i had an array with values "2,2,3,4" and i executed this function it would return true wheras if i had an array with values "1,3,3" and i executed the function it would return false.
can anyone help?

Posted: Thu Apr 07, 2005 10:20 am
by timvw
untested

Code: Select all

function foo($array)
{
  return count($array) == count(array_unique($array));
}

Posted: Thu Apr 07, 2005 11:13 am
by dannymc1983
just tested it and it works, thanks!