Finding sum of digits of a number until sum becomes single digit | Driver program to test the above function
< ? php function digSum ( $ n ) { if ( $ n == 0 ) return 0 ; return ( $ n % 9 == 0 ) ? 9 : ( $ n % 9 ) ; } $ n = 9999 ; echo digSum ( $ n ) ; ? >