Judging constellations is very simple. We need to count all the dates and time periods of each week, and then get the dates for query. I will give you two examples below, students in need can refer to them.
Horoscope: I wrote this based on this timeline, which may not be accurate.
'Aquarius'=>'(1/22-2/21)', 'Pisces'=>'(2/22-3/21)',
'Aries'=>'(3/22-4/21)', 'Taurus'=>'(4/22-5/21)',
'Gemini'=>'(5/22-6/21)', 'Cancer'=>'(6/22-7/21)',
'Leo'=>'(7/22-8/21)', 'Virgo'=>'(8/22-9/21)',
'Libra'=>'(9/22-10/21)', 'Scorpio'=>'(10/22-11/21)',
'Sagittarius'=>'(11/22-12/21)', 'Capricorn'=>'(12/22-1/21)'
Determine the horoscope function based on the date
The code is as follows | Copy code | ||||
|
The following is more comprehensive and can directly check age, zodiac sign, and constellation based on birthday
The code is as follows
| Copy code | ||||
/** function get_constellation($birth_month,$birth_date) {/**<🎜> <🎜>* Calculate your zodiac sign based on the year of your birthday<🎜> <🎜>*<🎜> <🎜>* @param int $birth_year<🎜> <🎜>* @return string<🎜> <🎜>*/<🎜> <🎜>function get_animal($birth_year)<🎜> <🎜>{<🎜> <🎜>//1900 is the Year of the Rat<🎜> <🎜>$animal = array(<🎜> <🎜> ‘Zi Shu’, ‘Chou Niu’, ‘Yin Hu’, ‘Mao Rabbit’, ‘Chen Long’, ‘Si Snake’, <🎜> <🎜> ‘Wuma’, ‘Weiyang’, ‘Shenmonkey’, ‘Yourooster’, ‘Xudog’, ‘Haizhu’<🎜> <🎜> );<🎜> <🎜> <🎜> <🎜>$my_animal = ($birth_year-1900)%12;<🎜> <🎜>return $animal[$my_animal];<🎜> <🎜>}<🎜> <🎜> /**<🎜> <🎜>* Calculate age based on birthday<🎜> <🎜>*<🎜> <🎜>* Using Unix timestamp calculation is the most accurate, but it is not easy to handle cases born before 1970<🎜> <🎜>* We also have to consider the issue of leap years, so we will temporarily abandon this method of development and keep our thoughts <🎜> <🎜>*<🎜> <🎜>* @param int $birth_year<🎜> <🎜>* @param int $birth_month<🎜> <🎜>* @param int $birth_date<🎜> <🎜>* @return int<🎜> <🎜>*/<🎜> <🎜>function get_age($birth_year,$birth_month,$birth_date)<🎜> <🎜>{<🎜> <🎜>$now_age = 1; //Actual age, calculated as 1 year old at birth<🎜> <🎜>$full_age = 0; //One year old, this variable is stored and can be modified at any time according to the specific situation<🎜> <🎜> <🎜> <🎜>$now_year = date('Y',time());<🎜> <🎜>$now_date_num = date('z',time()); //The day of the year<🎜> <🎜>$birth_date_num = date('z',mktime(0,0,0,$birth_month,$birth_date,$birth_year));<🎜> <🎜> <🎜> <🎜>$difference = $now_date_num - $birth_date_num;<🎜> <🎜>if ($difference > 0) { $full_age = $now_year - $birth_year; } else { $full_age = $now_year - $birth_year - 1; } $now_age = $full_age + 1; return $now_age; } ?> http://www.bkjia.com/PHPjc/628740.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628740.htmlTechArticleJudging constellations is very simple. We need to count all the date and time periods of each week, and then get the date for query. Okay, let me give you two examples below. Students in need can refer to it... |