Find even occurring elements in an array of limited range | Function to find the even occurring elements in given array ; do for each element of array ; left - shift 1 by value of current element ; Toggle the bit everytime element gets repeated ; Traverse array again and use _xor to find even occurring elements ; left - shift 1 by value of current element ; Each 0 in _xor represents an even occurrence ; print the even occurring numbers ; set bit as 1 to avoid printing duplicates ; Driver code
< ? php function printRepeatingEven ( $ arr , $ n ) { $ _xor = 0 ; $ pos ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ pos = 1 << $ arr [ $ i ] ; $ _xor ^= $ pos ; } for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ pos = 1 << $ arr [ $ i ] ; if ( ! ( $ pos & $ _xor ) ) { echo $ arr [ $ i ] , " " ; $ _xor ^= $ pos ; } } } $ arr = array ( 9 , 12 , 23 , 10 , 12 , 12 , 15 , 23 , 14 , 12 , 15 ) ; $ n = sizeof ( $ arr ) ; printRepeatingEven ( $ arr , $ n ) ; ? >