Implement * , | Function to flip the sign using only " + " operator ( It is simple with ' * ' allowed . We need to do a = ( - 1 ) * a ; If sign is + ve turn it - ve and vice - versa ; Check if a and b are of different signs ; Function to subtract two numbers by negating b and adding them ; Negating b ; Function to multiply a by b by adding a to itself b times ; because algo is faster if b < a ; Adding a to itself b times ; Check if final sign must be - ve or + ve ; Function to divide a by b by counting how many times ' b ' can be subtracted from ' a ' before getting 0 ; Negating b to subtract from a ; Subtracting divisor from dividend ; Check if a and b are of similar symbols or not ; Driver code
< ? php function flipSign ( $ a ) { $ neg = 0 ; $ tmp = $ a < 0 ? 1 : -1 ; while ( $ a != 0 ) { $ neg += $ tmp ; $ a += $ tmp ; } return $ neg ; } function areDifferentSign ( $ a , $ b ) { return ( ( $ a < 0 && $ b > 0 ) || ( $ a > 0 && $ b < 0 ) ) ; } function sub ( $ a , $ b ) { return $ a + flipSign ( $ b ) ; } function mul ( $ a , $ b ) { if ( $ a < $ b ) return mul ( $ b , $ a ) ; $ sum = 0 ; for ( $ i = abs ( $ b ) ; $ i > 0 ; $ i -- ) $ sum += $ a ; if ( $ b < 0 ) $ sum = flipSign ( $ sum ) ; return $ sum ; } function division ( $ a , $ b ) { $ quotient = 0 ; $ divisor = flipSign ( abs ( $ b ) ) ; for ( $ dividend = abs ( $ a ) ; $ dividend >= abs ( $ divisor ) ; $ dividend += $ divisor ) $ quotient ++ ; if ( areDifferentSign ( $ a , $ b ) ) $ quotient = flipSign ( $ quotient ) ; return $ quotient ; } print ( " Subtraction ▁ is ▁ " . sub ( 4 , -2 ) . " STRNEWLINE " ) ; print ( " Product ▁ is ▁ " . mul ( -9 , 6 ) . " STRNEWLINE " ) ; list ( $ a , $ b ) = array ( 8 , 2 ) ; if ( $ b ) print ( " Division ▁ is ▁ " . division ( $ a , $ b ) ) ; else print ( " Exception ▁ : - ▁ Divide ▁ by ▁ 0" ) ; ? >