<?php
$num = 14597;
$sum=0; $rem=0;
for ($i =0; $i<=strlen($num);$i++)
{
$rem=$num%10;
$sum = $sum + $rem;
$num=$num/10;
}
echo "Sum of digits 14597 is $sum";
?>
<?php
// PHP Code to compute sum
// of digits in number.
// Function to get
// $sum of digits
function getsum($n)
{
$sum = 0;
while ($n != 0)
{
$sum = $sum + $n % 10;
$n = $n/10;
}
return $sum;
}
// Driver Code
$n = 687;
$res = getsum($n);
echo("$res");
?>