话说,今天做项目要求计算星座

日期格式为2019-1-22

function get_xz($birthday) {

    $arr_day = explode('-', $birthday);
    $month = $arr_day[1];
    $day = $arr_day[2];
    
    if($month < 1 or $month > 12 or $day < 1 or $day > 31) return false; 

    $xz_array = 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"=>"摩羯座")
    );
    foreach ($xz_array[(int)$month-1] as $xz_key => $xz_name);
    if ($day < $xz_key) :
        foreach ($xz_array[($month-2 < 0)?$month = 11:$month -= 2] as $xz_key => $xz_name);
    endif;
    return $xz_name;
}