[SOLVED] array function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dannymc1983
Forum Commoner
Posts: 80
Joined: Wed Feb 16, 2005 7:24 am

[SOLVED] array function

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

untested

Code: Select all

function foo($array)
{
  return count($array) == count(array_unique($array));
}
dannymc1983
Forum Commoner
Posts: 80
Joined: Wed Feb 16, 2005 7:24 am

Post by dannymc1983 »

just tested it and it works, thanks!
Post Reply