Check for duplicate element in array


/ Published in: PHP
Save to your folder(s)

Parameters: $array - haystack, $find-value - needle to check for duplicates


Copy this code and paste it in your HTML
  1. function count_duplicates($array, $find_value) {
  2. $counter = 0;
  3. foreach($array as $value) {
  4. if($value == $find_value) {
  5. $counter++;
  6. }
  7. }
  8. return $counter;
  9. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.