php如何通过出生月份日期来计算星座
php语法如何通过输入月份和日期获取个人星座,下面编程教程网小编给大家简单介绍一下具体实现方法!
示列代码:
function getConstellation($month, $day){
if(($month < 1 || $month > 12) || ($day < 1 || $day > 31)) return false;
$constellations = [
['20' => '水瓶座'], ['19' => '双鱼座'], ['21' => '白羊座'], ['20' => '金牛座'],
['21' => '双子座'], ['22' => '巨蟹座'], ['23' => '狮子座'], ['23' => '处女座'],
['23' => '天秤座'], ['24' => '天蝎座'], ['22' => '射手座'], ['22' => '魔羯座']
];
list($constellation_key, $constellation_value) = each($constellations[(int)$month - 1]);
if($day < $constellation_key){
list($constellation_key, $constellation_value) =
each($constellations[($month - 2 < 0) ? $month = 11 : $month -= 2]);
}
return $constellation_value;
}
echo getConstellation(5,12);
echo getConstellation(1,6);
以上是编程学习网小编为您介绍的“php如何通过出生月份日期来计算星座”的全面内容,想了解更多关于 php入门 内容,请继续关注编程基础学习网。