PHP 获取星座

网上PHP获取星座的代码无法兼容PHP7.2+
使用以下代码即可

function get_xingzuo($month, $day)
{
    // 检查参数有效性
    if ($month < 1 || $month > 12 || $day < 1 || $day > 31)
    {
        return (false);
    }
    // 星名称以及开始日期
    $signs = array(
        array("20" => "宝瓶"),
        array("19" => "双鱼"),
        array("21" => "白羊"),
        array("20" => "金牛"),
        array("21" => "双子"),
        array("22" => "巨蟹"),
        array("23" => "狮子"),
        array("23" => "处女"),
        array("23" => "天秤"),
        array("24" => "天蝎"),
        array("22" => "射手"),
        array("22" => "摩羯"),
    );

    $xingzuo = $signs[(int) $month - 1];
    foreach ($xingzuo as $key => $value)
    {
        $sign_start = $key;
        $sign_name  = $value;
    }
    if ($day < $sign_start)
    {
        if ($month - 2 < 0)
        {
            $month = 11;
        }
        else
        {
            $month -= 2;
        }
        $xingzuo = $signs[$month];
        foreach ($xingzuo as $key => $value)
        {
            $sign_start = $key;
            $sign_name  = $value;
        }
    }
    return $sign_name;
}

相关文章

此处评论已关闭