Swap three variables without using temporary variable | Assign c ' s ▁ value ▁ to ▁ a , ▁ a ' s value to b and b 's value to c. ; Store XOR of all in a ; After this , b has value of a ; After this , c has value of b ; After this , a has value of c ; Driver code ; Calling Function
< ? php function swapThree ( & $ a , & $ b , & $ c ) { $ a = $ a ^ $ b ^ $ c ; $ b = $ a ^ $ b ^ $ c ; $ c = $ a ^ $ b ^ $ c ; $ a = $ a ^ $ b ^ $ c ; } $ a = 10 ; $ b = 20 ; $ c = 30 ; echo " Before ▁ swapping ▁ a ▁ = ▁ " , $ a , " , ▁ b ▁ = ▁ " , $ b , " , ▁ c ▁ = ▁ " , $ c , " STRNEWLINE " ; swapThree ( $ a , $ b , $ c ) ; echo " After ▁ swapping ▁ a ▁ = ▁ " , $ a , " , ▁ b ▁ = ▁ " , $ b , " , ▁ c ▁ = ▁ " , $ c , " STRNEWLINE " ; ? >