Heim >Backend-Entwicklung >PHP-Tutorial >php实现水仙花
<br />
class Armstrong {
static function index(){
for ( $i = 100; $i
echo self::is_armstrong($i) ? $i . '
' : '';
}
}
static function is_armstrong($num){
$s = 0;
$k = strlen($num);
$d = str_split($num);
foreach ($d as $r) {
$s += bcpow($r, $k);
}
return $num == $s;
}
}
Armstrong::index();
?>