从整数数组中返回第一个重复元素的最佳方法是什么?
例:
给定阵列[12,46,244,12,83,48,98,233,26,91,119,148,98].
在这种情况下,返回值是12.
如何才能做到这一点?
# temp array $array_help = array(); # run over the array foreach ($array as $val) { if (isset($array_help[$val])) # found if is set already ! return $val; else # its the first time this value appear $array_help[$val] = 1; }