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 comment

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