<?php $num=123; $sum=0; while($num>0) { $sum=$sum+$num%10; $num/=10 } echo"sum of digit 123 is $sum"; ?>