function armstrong($n) {
$reminder = 0;
$sum = 0;
$total_digits = strlen($n);
while ($n > 0) {
$reminder = $n % 10;
$sum += pow($reminder, $total_digits);
$n = $n / 10;
}
return $sum;
}
$n = 153; // 1*1*1 + 5*5*5 + 3*3*3 = 153
if ($n == armstrong($n))
echo "Armstrong number\n";
else
echo "Not armstrong number\n";
$n = 9474; // 9*9*9*9 + 4*4*4*4 + 7*7*7*7 + 4*4*4*4 = 9474
if ($n == armstrong($n))
echo "Armstrong number\n";
else
echo "Not armstrong number\n";
/*
run:
Armstrong number
Armstrong number
*/