This article describes the user's birth date to calculate the age/Zodiac/constellation of various program instance code, friends do not enter the reference
Calculate age
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"; }
The zodiac is calculated by year
<?php/** * calculation. Zodiac * * @param int $year Year * @return str * /function Get_animal ($year) { c13/> $animals = Array ( ' rat ', ' ox ', ' tiger ', ' Rabbit ', ' dragon ', ' Snake ', ' horse ', ' sheep ', ' monkey ', ' chicken ', ' dog ', ' pig ' ); $key = ($year -1900)%; return $animals [$key]; }echo Get_animal (1990); Ma Echo get_animal (); Tiger
Calculate constellations based on birthdays
<?php/** * calculation. Constellation * * @param int $month month * @param int $day Date * @return str */ function g Et_constellation ($month, $day) {$signs = array (' + ' = ' Aquarius '), Array (' + ' = ' pisces '), Array (' (' = ' + ' aries '), Array (' + ' = ' Taurus '), Array (' + ' + ' Gemini '), Array (' + ' + ' cancer '), array (' + ' = ') Leo '), Array (' + ' = ' virgo '), array (' + ' = ' libra '), Array (' ' + ' = ' Scorpio '), Array (' + ' + ' sagittarius '), Array (' + ' = ' capricorn ') ; $key = (int) $month-1; List ($startSign, $signName) = each ($signs [$key]); if ($day < $startSign) { $key = $month-2 < 0? $month = one: $month-= 2; List ($startSign, $signName) = each ($signs [$key]); } return $signName; }echo Get_constellation (a); Sagittarius Echo get_constellation (6, 6); Gemini
Related articles:
PHP based on birthday calculation age (years)
How PHP calculates age based on birthdays