function armstrong($n) {
$result = $remainder = 0;
while($n > 0) {
$remainder = $n % 10;
$n = $n / 10;
$result += $remainder * $remainder * $remainder;
}
return $result;
}
// 153 = 1*1*1 + 5*5*5 + 3*3*3 = 153 = armstrong
for ($i = 1; $i <= 500; $i++)
if ($i == armstrong($i))
echo $i . "\n";
/*
run:
1
153
370
371
407
*/