Compare Multiple Strings in Search of Duplicates
Moderator: General Moderators
Compare Multiple Strings in Search of Duplicates
I have six variable variables. It is OK if multiple variables have 'NULL' values, but, of those with values, I want to make sure that none have duplicate values. In other words, it is OK for both variable1 and variable2 to be equal to NULL, but I don't want variable1 and variable2 to have a value of "Tom". Any ideas on how best to compare the strings based on these requirements?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
you could do
you can change that to $new[$val] = $new[$val]++ to count how many times a option is duplicated too!
Code: Select all
foreach ($array as $val)
{
if (false !== isset($new[$val]))
$new[$val] = 'set';
else
//DUPLICATE AHHHHHH
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
if($array == array_unique($array)) { echo 'no duplicates there were, matey.'; } else { echo 'ya have duplicates matey.'; }