Finding sum of digits of a number until sum becomes single digit | PHP program to find sum of digits of a number until sum becomes single digit . ; Loop to do sum while sum is not less than or equal to 9 ; Driver Code
< ? php function digSum ( $ n ) { $ sum = 0 ; while ( $ n > 0 $ sum > 9 ) { if ( $ n == 0 ) { $ n = $ sum ; $ sum = 0 ; } $ sum += $ n % 10 ; $ n = ( int ) $ n / 10 ; } return $ sum ; } $ n = 1234 ; echo digSum ( $ n ) ; ? >