计算 星座 php
<?php
/**
* 计算.星座
*
* @param int $month 月份
* @param int $day 日期
* @return str
*/
function get_constellation($month, $day){
$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'=>'摩羯座')
);
$key = (int)$month - 1;
list($startsign, $signname) = each($signs[$key]);
if( $day < $startsign ){
$key = $month - 2 < 0 ? $month = 11 : $month -= 2;
list($startsign, $signname) = each($signs[$key]);
}
return $signname;
}
echo get_constellation(12, 11); // 射手座
echo get_constellation(6, 6); // 双子座
2. [php]代码 <?php
/**
* 计算.星座
*
* @param int $month 月份
* @param int $date 年份
* @return str
*/
function get_constellation($month, $date){
$constellations = array(
'水瓶座', '双鱼座', '白羊座', '金牛座', '双子座', '巨蟹座',
'狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座'
);
if( $date <= 22 ){
if( 1 != $month ){
$constellation = $constellations[$month - 2];
}else{
$constellation = $constellations[11];
}
}else{
$constellation = $constellations[$month - 1];
}
return $constellation;
}
echo get_constellation(12, 11); // 射手座
echo get_constellation(6, 6); // 双子座
以上就是计算 星座 php的内容。