Find elements of array using XOR of consecutive elements | Function to find the array elements using XOR of consecutive elements ; first element a i . e elements [ 0 ] = a ; To get the next elements we have to calculate xor of previous elements with given xor of 2 consecutive elements . e . g . if a ^ b = k1 so to get b xor a both side . b = k1 ^ a ; Printing the original array elements ; Driver Code
< ? php function getElements ( $ a , & $ arr , & $ n ) { $ elements [ 0 ] = $ a ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ elements [ $ i + 1 ] = $ arr [ $ i ] ^ $ elements [ $ i ] ; } for ( $ i = 0 ; $ i < $ n + 1 ; $ i ++ ) { echo ( $ elements [ $ i ] . " " ) ; } } $ arr = array ( 13 , 2 , 6 , 1 ) ; $ n = sizeof ( $ arr ) ; $ a = 5 ; getElements ( $ a , $ arr , $ n ) ; ? >