Print uncommon elements from two sorted arrays | PHP program to find uncommon elements of two sorted arrays ; If not common , prsmaller ; Skip common element ; printing remaining elements ; Driver code
< ? php function printUncommon ( $ arr1 , $ arr2 , $ n1 , $ n2 ) { $ i = 0 ; $ j = 0 ; $ k = 0 ; while ( $ i < $ n1 && $ j < $ n2 ) { if ( $ arr1 [ $ i ] < $ arr2 [ $ j ] ) { echo $ arr1 [ $ i ] . " " ; $ i ++ ; $ k ++ ; } else if ( $ arr2 [ $ j ] < $ arr1 [ $ i ] ) { echo $ arr2 [ $ j ] . " " ; $ k ++ ; $ j ++ ; } else { $ i ++ ; $ j ++ ; } } while ( $ i < $ n1 ) { echo $ arr1 [ $ i ] . " " ; $ i ++ ; $ k ++ ; } while ( $ j < $ n2 ) { echo $ arr2 [ $ j ] . " " ; $ j ++ ; $ k ++ ; } } $ arr1 = array ( 10 , 20 , 30 ) ; $ arr2 = array ( 20 , 25 , 30 , 40 , 50 ) ; $ n1 = sizeof ( $ arr1 ) ; $ n2 = sizeof ( $ arr2 ) ; printUncommon ( $ arr1 , $ arr2 , $ n1 , $ n2 ) ; ? >