PHP function to determine zodiac sign based on specific date_PHP tutorial

WBOY
Release: 2016-07-13 10:12:37
Original
1167 people have browsed it

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;
}
Copy after login

Function call example:

echo constellation(4, 20);
Copy after login

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!