PHP – Check if duplicated values exists in array

The following function could help you to check if there is any duplicated values in an given array.

function has_dupes($array) {
  $dupe_array = array();
  foreach($array as $val){
    if(++$dupe_array[$val] > 1){
      return true;
    }
  }
  return false;
}

Done =)

Reference: StackOverflow – php: check if an array has duplicates

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.