The below program checks for an Armstrong number using a loop. The PHP echo statement is used to output the result on the screen. A number is called as an Armstrong number if the sum of the cubes of its digits is equal to the number itself.
Armstrong Number:
abc = (a*a*a) + (b*b*b) + (c*c*c)
Example: 0, 1, 153, 371, 407, 471, etc.
Example
<!DOCTYPE html>
<html>
<body>
<?php
$n=371;
$sum=0;
$i=$n;
while($i!=0)
{
$x=$i%10;
$sum=$sum+$x*$x*$x;
$i=$i/10;
}
if($n==$sum)
{
echo "$n is an Armstrong Number.";
}
else
{
echo "$n is not an Armstrong Number.";
}
?>
</body>
</html>
Output371 is an Armstrong Number.