<!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>