php calculates the function code for the zodiac

  • 2020-05-19 04:27:19
  • OfStack

Core code:
 
<?php 
/* 
*  Calculate the function of the constellation  string get_zodiac_sign(string month, string day) 
*  Input: month, date  
*  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); 
//  The name of the constellation and the 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 the function  
?> 

Related articles: