Home >Backend Development >PHP Tutorial >Calculate zodiac signs

Calculate zodiac signs

WBOY
WBOYOriginal
2016-07-25 08:50:231526browse
  1. /**
  2. * Calculation. Zodiac
  3. *
  4. * @param int $year Year
  5. * @return str
  6. */
  7. function get_animal($year){
  8. $animals = array(
  9. 'Rat', 'Ox', 'Tiger', 'Rabbit', 'Dragon ', 'Snake',
  10. 'Horse', 'Sheep', '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
Copy code


Statement:
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