Home  >  Article  >  Backend Development  >  PHP function to determine zodiac sign based on specific date_PHP tutorial

PHP function to determine zodiac sign based on specific date_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:371142browse

PHP function to determine the zodiac sign based on a specific date

It seems to be quite popular to discuss zodiac signs now. The author below shares a function that uses PHP to determine which zodiac sign a specified date belongs to. The specific function code is as follows:

function constellation($month,$day){
	//检查参数有效性 http://www.phpernote.com/
	if($month<1||$month>12||$day<1||$day>31) return false;	
	//星座名称以及开始日期
	$constellations=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"=>"摩羯座")
	);
	list($constellation_start,$constellation_name)=each($constellations[(int)$month-1]);
	if($day<$constellation_start){
		list($constellation_start,$constellation_name)=each($constellations[($month-2<0)?$month=11:$month-=2]);
	}
	return $constellation_name;
}

Function call example:

echo constellation(4, 20);

Articles you may be interested in

  • How to obtain zodiac signs, zodiac signs and constellation information based on date or time stamp using php
  • php extract ID card number Birthday date and function to verify whether a minor is a minor
  • php function to calculate how many years, months, and days are apart between two dates
  • php function to calculate how many days (days) are the difference between two dates Function
  • PHP number judgment function
  • How does PHP judge whether a gif image is a dynamic picture (animation)
  • php method to get each month within a certain period of time and return An array composed of these months
  • php function that calculates the current week of the year or month

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/919715.htmlTechArticlePHP’s function to determine the zodiac sign based on a specific date seems to be very popular now to discuss zodiac signs. The author below shares a method using PHP A function that determines which zodiac sign a specified date belongs to. Specific function code...
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