Created
April 19, 2017 16:43
-
-
Save farhadhp/75b4244a5f8535800c3112cd01d51dbd to your computer and use it in GitHub Desktop.
has_duplicated_array : An simple function to check if given array contains duplicated values
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 | |
/* | |
* Author : Farhad Hassan Pour (https://farhadhp.github.io/) | |
*/ | |
function has_duplicated_array($arr) { | |
$count_value = array_count_values($arr); | |
rsort($count_value); | |
return $count_value[0] > 1; | |
} | |
/* | |
* Example | |
*/ | |
$my_array = array('a','b','c','d','e','b','b','d','c','e','e','e','e'); | |
if(has_duplicated_array($my_array)) { | |
echo 'duplicat'; | |
}else{ | |
echo 'not duplicat!'; | |
} | |
// output : duplicat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And a bit shorter: