最後更新日期:2021年08月01日
PHP程式練習
如何輸入生日時間,而產生生日所對應的星座呢?
輸入方式為unixtime,關於unixtime有另外其他文章可以參考
<?PHP
# 輸入unix time換算星座
function unixtime_to_star_sign($unixtime)
{
$month = intval(date('m',$unixtime));
$day = intval(date('d',$unixtime));
# 檢查有效性
if ( $month < 1 || $month > 12 || $day < 1 || $day > 31 )
{
return ('ERROR’);
}
# 星座名稱以即開始日期
$signs = array(
array( "20" => "aquarius"),
array( "19" => "pisces"),
array( "21" => "aries"),
array( "20" => "taurus"),
array( "21" => "gemini"),
array( "22" => "cancer"),
array( "23" => "leo"),
array( "23" => "virgo"),
array( "23" => "libra"),
array( "24" => "scorpio"),
array( "22" => "sagittarius"),
array( "22" => "capricornus")
);
# 判別所屬星座
list($sign_start, $sign_name) = each($signs[(int)$month-1]);
if ($day < $sign_start)
{
list($sign_start, $sign_name) = each($signs[($month -2 < 0) ? $month = 11: $month -= 2]);
}
return $sign_name;
}
如果您喜歡我的文章或是我的文章對您有幫助,歡迎幫我點讚或分享,謝謝您的觀看