Q:

Write a PHP program to check a flat list for duplicate values. Returns true if duplicate values exists and false if values are all unique

0

Write a PHP program to check a flat list for duplicate values. Returns true if duplicate values exists and false if values are all unique.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function has_Duplicates($items)
{
    if (count($items) > count(array_unique($items)))
      return 1;
    else
      return 0;
}
print_r(has_Duplicates([1, 2, 3, 4, 5, 5])); 
echo "\n";
print_r(has_Duplicates([1, 2, 3, 4, 5])); 

?>

Sample Output:

1
0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now