text: Find number of pairs in an array such that their XOR is 0 | Function to calculate the answer ; Finding the maximum of the array ; Creating frequency array With initial value 0 ; Traversing through the array ; Counting frequency ; Traversing through the frequency array ; Calculating answer ; Driver Code ; Function calling
code: < ? php function calculate ( $ a , $ n ) { $ maximum = max ( $ a ) ; $ frequency = array_fill ( 0 , $ maximum + 1 , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ frequency [ $ a [ $ i ] ] += 1 ; } $ answer = 0 ; for ( $ i = 0 ; $ i < ( $ maximum ) + 1 ; $ i ++ ) { $ answer = $ answer + $ frequency [ $ i ] * ( $ frequency [ $ i ] - 1 ) ; } return $ answer / 2 ; } $ a = array ( 1 , 2 , 1 , 2 , 4 ) ; $ n = count ( $ a ) ; echo ( calculate ( $ a , $ n ) ) ; ? >