Get the sum of digits in PHP

后端 未结 13 2798
攒了一身酷
攒了一身酷 2020-11-29 10:45

How do I find the sum of all the digits in a number in PHP?

13条回答
  •  被撕碎了的回忆
    2020-11-29 11:30

    Here's the code.. Please try this

       1)
    
         {
          $temp=$temp/10;
    
            $d++;
             }
    
         echo "Digits Are : $d 
    "; for (;$num>1;) { $d=$num%10; $num=$num/10; $sum=$sum+$d; } echo "Sum of Digits is : $sum"; ?>

提交回复
热议问题