每个星座的出生日期php,php中根据生日判断星座、生肖程序代码

编程入门 行业动态 更新时间:2024-10-08 18:31:18

每个<a href=https://www.elefans.com/category/jswz/34/1754851.html style=星座的出生日期php,php中根据生日判断星座、生肖程序代码"/>

每个星座的出生日期php,php中根据生日判断星座、生肖程序代码

/**

* 根据生日中的月份和日期来计算所属星座

*

* @param int $birth_month

* @param int $birth_date

* @return string

*/

function get_constellation($birth_month,$birth_date)

{

//判断的时候,为避免出现1和true的疑惑,或是判断语句始终为真的问题,这里统一处理成字符串形式

$birth_month = strval($birth_month);

$constellation_name = array(

'水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',

'狮子座','处女座','天秤座','天蝎座)','射手座','摩羯座'

);

if ($birth_date <= 22)

{

if ('1' !== $birth_month)

{

$constellation = $constellation_name[$birth_month-2];

}

else

{

$constellation = $constellation_name[11];

}

}

else

{

$constellation = $constellation_name[$birth_month-1];

}

return $constellation;

}

/**

* 根据生日中的年份来计算所属生肖

*

* @param int $birth_year

* @return string

*/

function get_animal($birth_year)

{

//1900年是子鼠年

$animal = array(

'子鼠','丑牛','寅虎','卯兔','辰龙','巳蛇',

'午马','未羊','申猴','酉鸡','戌狗','亥猪'

);

$my_animal = ($birth_year-1900)%12;

return $animal[$my_animal];

}

/**

* 根据生日来计算年龄

*

* 用Unix时间戳计算是最准确的,但不太好处理1970年之前出生的情况

* 而且还要考虑闰年的问题,所以就暂时放弃这种方式的开发,保留思想

*

* @param int $birth_year

* @param int $birth_month

* @param int $birth_date

* @return int

*/

function get_age($birth_year,$birth_month,$birth_date)

{

$now_age = 1; //实际年龄,以出生时为1岁计

$full_age = 0; //周岁,该变量放着,根据具体情况可以随时修改

$now_year   = date('Y',time());

$now_date_num  = date('z',time()); //该年份中的第几天

$birth_date_num = date('z',mktime(0,0,0,$birth_month,$birth_date,$birth_year));

$difference = $now_date_num - $birth_date_num;

if ($difference > 0)

{

$full_age = $now_year - $birth_year;

}

else

{

$full_age = $now_year - $birth_year - 1;

}

$now_age = $full_age + 1;

return $now_age;

}

?>

更多推荐

每个星座的出生日期php,php中根据生日判断星座、生肖程序代码

本文发布于:2024-02-07 07:20:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1754697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:星座   出生日期   生肖   程序代码   生日

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!