kernelgpf Posted May 16, 2007 Share Posted May 16, 2007 Title says it all- I need to check if there are more than one of the same string in an array. Does anyone know of a function? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/51738-function-to-check-for-multiple-instances-of-a-string-in-an-array/ Share on other sites More sharing options...
effigy Posted May 16, 2007 Share Posted May 16, 2007 "Same string" meaning the entirety of each value, not a partial match? <pre> <?php function array_has_dupes (&$array) { $tmp = array_unique($array); return count($array) == count($tmp) ? 0 : 1 ; } $pure_array = array('a', 'b', 'c', 1, 2, 3); $dupe_array = array('a', 'b', 'c', 1, 2, 'a'); echo array_has_dupes($pure_array) ? 'Y' : 'N' ; echo '<br>'; echo array_has_dupes($dupe_array) ? 'Y' : 'N' ; ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/51738-function-to-check-for-multiple-instances-of-a-string-in-an-array/#findComment-254839 Share on other sites More sharing options...
kernelgpf Posted May 16, 2007 Author Share Posted May 16, 2007 Mhmm, entirety of value.. thanks, I'll try it out. Quote Link to comment https://forums.phpfreaks.com/topic/51738-function-to-check-for-multiple-instances-of-a-string-in-an-array/#findComment-254841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.