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 enter the reference age, the code is as follows: functionbirthday ($ mydate

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

Age,The code is as follows:

  1. Function birthday ($ mydate ){
  2. $ Birth = $ mydate;
  3. List ($ by, $ bm, $ bd) = explode ('-', $ birth );
  4. $ Cm = date ('N ');
  5. $ Cd = date ('J ');
  6. $ Age = date ('Y')-$ by-1;
  7. If ($ cm> $ bm | $ cm ==$ bm & $ cd> $ bd) $ age ++;
  8. Return $ age;
  9. // Echo "birthday: $ birthn age: $ agen ";
  10. }

Calculate the zodiac based on the year,The code is as follows:

  1. /**
  2. * Computing. Zodiac
  3. *
  4. * @ Param int $ year
  5. * @ Return str
  6. */
  7. Function get_animal ($ year ){
  8. $ Animals = array (
  9. 'Rat ', 'ox', 'Tiger ', 'rabbit', 'Dragon ', 'Snake ',
  10. 'Ma', 'Yang', 'Monkey ', 'Chicken', 'dog', 'pig'
  11. );
  12. $ Key = ($ year-1900) % 12;
  13. Return $ animals [$ key];
  14. }
  15. Echo get_animal (1990); // horse
  16. Echo get_animal (2010); // Tiger

Calculate the Constellation based on the birthday,The code is as follows:

  1. /**
  2. * Computing. constellation
  3. *
  4. * @ Param int $ month
  5. * @ Param int $ day date
  6. * @ Return str
  7. */
  8. Function get_constellation ($ month, $ day ){
  9. $ Signs = array (
  10. Array ('20' => 'trease'), array ('19' => 'pisces '),
  11. Array ('21' => 'Aries'), array ('20' => 'Taurus '),
  12. Array ('21' => 'gemine'), array ('22' => 'loan '),
  13. Array ('23' => 'Leo '), array ('23' => 'virgo '),
  14. Array ('23' => 'Libra '), array ('24' => 'Scorpio '),
  15. Array ('22' => 'Sagittarius '), array ('22' => 'capricorn ')
  16. );
  17. $ Key = (int) $ month-1;
  18. List ($ startSign, $ signName) = each ($ signs [$ key]);
  19. If ($ day <$ startSign ){
  20. $ Key = $ month-2 <0? $ Month = 11: $ month-= 2;
  21. List ($ startSign, $ signName) = each ($ signs [$ key]);
  22. }
  23. Return $ signName;
  24. }
  25. Echo get_constellation (12, 11); // Sagittarius
  26. Echo get_constellation (6, 6); // Gemini

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.