PHP Online Compiler
Example: Sum of Digits of a Number PHP Program using While loop
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php $x = 1569; $sum = 0; $m = NULL; echo "The sum of ", $x, " digits is = "; // It will calculate the sum of each digit of the input number while ($x > 0) { $m = $x % 10; $m = intval ($m); $sum = $sum + $m; $x = $x / 10; $x = intval ($x); } // It will print the final output; echo $sum; ?>
Output
Clear
ADVERTISEMENTS