Replace every element of the array with BitWise XOR of all other | Function to replace the elements ; Calculate the xor of all the elements ; Replace every element by the xor of all other elements ; Driver code ; Print the modified array .
< ? php function ReplaceElements ( $ arr , $ n ) { $ X = 0 ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ X ^= $ arr [ $ i ] ; } for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ arr [ $ i ] = $ X ^ $ arr [ $ i ] ; } return $ arr ; } $ arr = array ( 2 , 3 , 3 , 5 , 5 ) ; $ n = sizeof ( $ arr ) ; $ arr1 = ReplaceElements ( $ arr , $ n ) ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { echo ( $ arr1 [ $ i ] . " " ) ; } ? >