Home  >  Article  >  Backend Development  >  PHP function code for calculating the twelve zodiac signs_PHP tutorial

PHP function code for calculating the twelve zodiac signs_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:31847browse

Core code:

Copy code The code is as follows:

/*
* Calculate the zodiac sign Function string get_zodiac_sign(string month, string day)
* Input: month, day
* Output: constellation name or error message
*/

function get_zodiac_sign($month, $day )
{
// Check parameter validity
if ($month < 1 || $month > 12 || $day < 1 || $day > 31)
return (false);
// Constellation name and start date
$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" => "Capricorn")
);
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;
}//End of function
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325719.htmlTechArticleCore code: Copy the code as follows: ?php /* * Function string to calculate the constellation get_zodiac_sign(string month, string day) * Input: month, date * Output: Constellation name or wrong...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn