PHP Compiler
<!DOCTYPE html> <html> <body> <?php $num = 12; $copyNum = $num; $total = 0; // Add Each digit from last digit while($copyNum != 0) { $total += $copyNum % 10; $copyNum = floor($copyNum / 10); } // result echo "Sum of digit of $num: $total"; ?> </body> </html>
OUTPUT
The sum of digit 12: 3
×

Save as Private