Php calculates the age/Zodiac/Constellation instance based on the birthday

Source: Internet
Author: User
This article introduces various program instance codes used to calculate the age and zodiac constellation based on the user's birthdate. if you do not want to go to the reference age calculation code, copy the code functionbi as follows...

This article introduces various program instance codes for age, Zodiac, and Constellation calculation based on the date of birth.


// Calculate the age

The code is as follows:
Function birthday ($ mydate ){
$ Birth = $ mydate;
List ($ by, $ bm, $ bd) = explode ('-', $ birth );
$ Cm = date ('N ');
$ Cd = date ('J ');
$ Age = date ('Y')-$ by-1;
If ($ cm> $ bm | $ cm ==$ bm & $ cd> $ bd) $ age ++;
Return $ age;
// Echo "birthday: $ birthn age: $ agen ";
}

Calculate the Chinese zodiac by year

The code is as follows:

/**
* Computing. Zodiac
*
* @ Param int $ year
* @ Return str
*/
Function get_animal ($ year ){
$ Animals = array (
'Rat ', 'ox', 'Tiger ', 'rabbit', 'Dragon ', 'Snake ',
'Ma', 'Yang', 'Monkey ', 'Chicken', 'dog', 'pig'
);
$ Key = ($ year-1900) % 12;
Return $ animals [$ key];
}

Echo get_animal (1990); // horse
Echo get_animal (2010); // Tiger

Calculate constellation based on birthday

The code is as follows:


/**
* Computing. constellation
*
* @ Param int $ month
* @ Param int $ day date
* @ Return str
*/
Function get_constellation ($ month, $ day ){
$ Signs = array (
Array ('20' => 'trease'), array ('19' => 'pisces '),
Array ('21' => 'Aries'), array ('20' => 'Taurus '),
Array ('21' => 'gemine'), array ('22' => 'loan '),
Array ('23' => 'Leo '), array ('23' => 'virgo '),
Array ('23' => 'Libra '), array ('24' => 'Scorpio '),
Array ('22' => 'Sagittarius '), array ('22' => 'capricorn ')
);
$ Key = (int) $ month-1;
List ($ startSign, $ signName) = each ($ signs [$ key]);
If ($ day <$ startSign ){
$ Key = $ month-2 <0? $ Month = 11: $ month-= 2;
List ($ startSign, $ signName) = each ($ signs [$ key]);
}
Return $ signName;
}

Echo get_constellation (12, 11); // Sagittarius
Echo get_constellation (6, 6); // Gemini



Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.