php如何通过出生月份日期来计算星座

2024年09月12日 建站教程

php语法如何通过输入月份和日期获取个人星座,下面web建站小编给大家简单介绍一下具体实现方法!

示列代码:

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);

本文链接:http://so.lmcjl.com/news/12842/

展开阅读全文
相关内容