星座
判断今天属于哪个星座
function constellation(){
$month = (int)date('m');
$day = (int)date('d');
// 所有星座
$constellations = [
'摩羯座','水瓶座', '双鱼座', '白羊座', '金牛座', '双子座',
'巨蟹座','狮子座', '处女座', '天秤座', '天蝎座', '射手座',
];
//设定星座结束日期的数组,对应上面星座
$endDays = [19, 18, 20, 20, 20, 21, 22, 22, 22, 22, 21, 21];
if($day <= $endDays[$month - 1]){ // 当前日期 <= 该当前月份的星座结束日期 则为该星座
$constellation = $constellations[$month - 1];
}else{
$constellation = empty($constellations[$month]) ? $constellations[0] : $constellations[$month];
}
return $constellation;
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: