Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if an array has duplicates
<?php
/**
* ===============================
* Check if array has duplicates
* ===============================
*/
$arr = [ 1, 2, 3, 3 ];
echo "Array does " . ( hasDuplicates($arr) ? '' : 'not ' ) . "have duplicates.";
/**
* Function to check array for duplicates
*
* @param array $value
*
* @return bool
*/
function hasDuplicates($value) {
return ( $value != array_unique($value) );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment