例子,php打印水仙花数。
 
<html>
<head>
  <title>php水仙花数函数--www.jb200.com</title>
</head>
<body>
<?php
 function winter($num)
 {
       if($num<1000){
       //定义个位
       $ge=$num%10;
       //定义十位
       $ten=(($num%100)-$ge) /10;
       //定义百位
       /*floor取整,忽略小数点后面的所有数*/
       $hundred=floor($num/100);
       $sum1=$ge*$ge*$ge+$ten*$ten*$ten+$hundred*$hundred*$hundred;
       if($sum1==$num){
               return 1;
                } else{
                        return 0;
                        }
               } else{
                       return -1;
                       }
         }
         if(winter(371)==-1) {
                 echo "大于1000的数";
            }else{
                  if(winter(371)) {
                          echo "Yes";
                          }  else{
                                  echo "No";
                                  }
}
?>
</body>
</html>
例2,php实现水仙花数