Home >Backend Development >PHP Tutorial >PHP function code to determine constellation based on date

PHP function code to determine constellation based on date

WBOY
WBOYOriginal
2016-07-25 08:54:291190browse
  1. function yige_constellation($month, $day) {

  2. // Check parameter validity
  3. if ($month < 1 || $month > 12 || $ day < 1 || $day > 31) return false;

  4. // Constellation name and start date

  5. $constellations = array(
  6. array( "20" => "Aquarius" ),
  7. array( "19" => "Pisces"),
  8. array( "21" => "Aries"),
  9. array( "20" => "Taurus"),
  10. array( "21" => "Gemini"),
  11. array( "22" => "Cancer"),
  12. array( "23" => "Leo"),
  13. array( "23" => "Virgo") ,
  14. array( "23" => "Libra"),
  15. array( "24" => "Scorpio"),
  16. array( "22" => "Sagittarius"),
  17. array( "22" => "Capricorn")
  18. );

  19. list($constellation_start, $constellation_name) = each($constellations[(int)$month-1]);

  20. if ($day < $constellation_start) list($constellation_start, $constellation_name) = each($constellations[($month -2 < 0) ? $month = 11: $month -= 2]);

  21. return $constellation_name;

  22. }

  23. //Call:

  24. echo yige_constellation(4, 20);

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