Example 1:
Copy Code code as follows:
<?php
For ($q =1 $q <=9; $q + +) {
For ($w =0 $w <=9; $w + +) {
For ($e =0 $e <=9; $e + +) {
if ($q * $q * $q + $w * $w * $w + $e * $e * $e = =
100* $q + 10* $w + $e) {
echo "$q $w $e." <p> ";
}
}
}
}
?>
Example 2:
Copy Code code as follows:
<?php
function cube ($n)
{
return $n * $n * $n;
}
function Is_narcissistic ($n)
{
$hundreds = Floor ($n/100); Break up hundreds
$tens = Floor ($n/10)% 10; Break out 10 bits
$ones = Floor ($n% 10); To break out a single digit
Return (BOOL) (Cube ($hundreds) +cube ($tens) +cube ($ones) = = $n);
}
for ($i = $i < 1000 + + $i)
{
if (is_narcissistic ($i))
echo $i. " \ n ";
}
?>
Example 3:
Copy Code code as follows:
<?php
Armstrong: A K-digit, the sum of the K-power of the number on each bit of it is equal to itself. (For example: 1^3 + 5^3 + 3^3 = 153)
Class Armstrong {
static function index () {
for ($i = $i < 100000; $i + +) {
echo Self::is_armstrong ($i)? $i. ' <br> ': ';
}
}
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 ();
Example 4:
Copy Code code as follows:
<title></title>
<body>
<?php
function Winter ($num)
{
if ($num <1000) {
Define Single-digit
$ge = $num% 10;
Define 10-bit
$ten = (($num%100)-$ge)/10;
Define Hundred
/*floor, ignoring all digits after the decimal point * *
$hundred =floor ($num/100);
$sum 1= $ge * $ge * $ge + $ten * $ten * $ten + $hundred * $hundred;
if ($sum 1== $num) {
return 1;
} else{
return 0;
}
} else{
return-1;
}
}
if (Winter (371) ==-1) {
echo "A number greater than 1000";
}else{
if (Winter (371)) {
echo "Yes";
}
else{
echo "No";
}
}
?>
</body>