Elements that occurred only once in the array | Function to find the elements that appeared only once in the array ; Sort the array ; Check for first element ; Check for all the elements if it is different its adjacent elements ; Check for the last element ; Driver code
< ? php function occurredOnce ( & $ arr , $ n ) { sort ( $ arr ) ; if ( $ arr [ 0 ] != $ arr [ 1 ] ) echo $ arr [ 0 ] . " ▁ " ; for ( $ i = 1 ; $ i < $ n - 1 ; $ i ++ ) if ( $ arr [ $ i ] != $ arr [ $ i + 1 ] && $ arr [ $ i ] != $ arr [ $ i - 1 ] ) echo $ arr [ $ i ] . " ▁ " ; if ( $ arr [ $ n - 2 ] != $ arr [ $ n - 1 ] ) echo $ arr [ $ n - 1 ] . " ▁ " ; } $ arr = array ( 7 , 7 , 8 , 8 , 9 , 1 , 1 , 4 , 2 , 2 ) ; $ n = sizeof ( $ arr ) ; occurredOnce ( $ arr , $ n ) ; ? >