d_r_sriram Posted April 22, 2009 Share Posted April 22, 2009 Hi Everybody-I have to implement a code that adds up 8 digits amongst itself till it doesnt get reduced to a single digit. for ex : i have to add 31031976 as 3+1+0+3+1+9+7+6=30=3+0=3.the input wud be always of 8 digits.can someone be kind enof to share the code..thanks in advance-Sriram Link to comment https://forums.phpfreaks.com/topic/155151-help-on-adding-digits/ Share on other sites More sharing options...
genericnumber1 Posted April 22, 2009 Share Posted April 22, 2009 I posted a solution to this a few weeks ago. <?php $number = 31031976; while($number > 9) { $number = array_sum(str_split($number)); } echo $number; From: http://www.phpfreaks.com/forums/index.php/topic,247632.msg1158771.html#msg1158771 Link to comment https://forums.phpfreaks.com/topic/155151-help-on-adding-digits/#findComment-816159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.