Created
October 28, 2013 09:51
-
-
Save Rudis1261/7194109 to your computer and use it in GitHub Desktop.
Checking whether an array contains duplicate values or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Let's define a simple array to display the function | |
$array = array("How", "Now", "Brown", "Cow", "With", "The", "Brown", "Fox"); | |
# Check if it contains a duplicate value? | |
if ( count($array) !== count(array_unique($array)) ) | |
{ | |
echo "Contains Duplicate"; | |
} | |
# What if it doesn't contain a duplicate value, what then? | |
else | |
{ | |
echo "Does not contain a duplicate"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment