Home > Backend Development > PHP Tutorial > PHP function sharing to determine constellation based on date_PHP tutorial

PHP function sharing to determine constellation based on date_PHP tutorial

WBOY
Release: 2016-07-13 10:37:32
Original
1208 people have browsed it

Copy code The code is as follows:

function yige_constellation($month, $day) {
// Check that the parameters are valid Sex
if ($month < 1 || $month > 12 || $day < 1 || $day > 31) return false;

// Constellation name and start date
$constellations = array(
array( "20" => "Aquarius"),
array( "19" => "Pisces"),
array( "21" => "Aries"),
array( "20" => "Taurus"),
array( "21" => "Gemini"),
array( "22" => "Cancer "),
array( "23" => "Leo"),
array( "23" => "Virgo"),
array( "23" => "Libra" ),
array( "24" => "Scorpio"),
array( "22" => "Sagittarius"),
array( "22" => "Capricorn")
);

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

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

return $constellation_name;
}

Call example:

Copy code The code is as follows:

echo yige_constellation(4, 20);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735238.htmlTechArticleCopy code The code is as follows: function yige_constellation($month, $day) { // Check parameter validity if ($ month 1 || $month 12 || $day 1 || $day 31) return false; // Constellation name and opening...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template