Copy Code code as follows:
<?php
/**
* PHP Age Calculation function
*
* parameter supports array parameters and standard Mysql date type arguments
* Params sample
* --------------------------------------------------
$BIRTHARR = Array (
' Year ' => ' 2000 ',
' Month ' => ' 11 ',
' Day ' => ' 3 '
);
$birthStr = ' 2000-11-03 ';
* --------------------------------------------------
* );
* @author It Tumbler <itbudaoweng@gmail.com>
* @copyright (c) 2011,2012 Just use it!
* @link It Tumbler http://yungbo.com
* @param string|array $birthday
* @return Number $age
*/
function Getage ($birthday) {
$age = 0;
$year = $month = $day = 0;
if (Is_array ($birthday)) {
Extract ($birthday);
} else {
if (Strpos ($birthday, '-')!== false) {
List ($year, $month, $day) = Explode ('-', $birthday);
$day = substr ($day, 0, 2); Get the "two chars in" Case of ' 2000-11-03 12:12:00 '
}
}
$age = Date (' Y ')-$year;
If date (' m ') < $month | | (Date (' m ') = = $month && date (' d ') < $day)) $age--;
return $age;
}