PHPIN.NET

 找回密码
 立即注册
查看: 5115|回复: 0

[高级进阶] PHP根据具体的日期判断星座的函数

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2015-4-3 20:18:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
PHP根据具体的日期判断星座的函数

  1. function constellation($month,$day){
  2.         //检查参数有效性
  3.         if($month<1||$month>12||$day<1||$day>31) return false;        
  4.         //星座名称以及开始日期
  5.         $constellations=array(
  6.                 array("20"=>"宝瓶座"),
  7.                 array("19"=>"双鱼座"),
  8.                 array("21"=>"白羊座"),
  9.                 array("20"=>"金牛座"),
  10.                 array("21"=>"双子座"),
  11.                 array("22"=>"巨蟹座"),
  12.                 array("23"=>"狮子座"),
  13.                 array("23"=>"处女座"),
  14.                 array("23"=>"天秤座"),
  15.                 array("24"=>"天蝎座"),
  16.                 array("22"=>"射手座"),
  17.                 array("22"=>"摩羯座")
  18.         );
  19.         list($constellation_start,$constellation_name)=each($constellations[(int)$month-1]);
  20.         if($day<$constellation_start){
  21.                 list($constellation_start,$constellation_name)=each($constellations[($month-2<0)?$month=11:$month-=2]);
  22.         }
  23.         return $constellation_name;
  24. }
复制代码
函数调用示例:
  1. echo constellation(4, 20);
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-20 02:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表