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★