Copy codeThe Code is as follows: <? Php
/**
* PHP age calculation function
*
* Parameters support parameter passing by array and standard Mysql date
* Params sample
*--------------------------------------------------
$ BirthArr = array (
'Year' => '123 ',
'Month' => '11 ',
'Day' => '3'
);
$ BirthStr = '2017-2000 ';
*--------------------------------------------------
*);
* @ 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 first two chars in case of '2017-11-03 12:12:00'
}
}
$ Age = date ('y')-$ year;
If (date ('M') <$ month | (date ('M') ==$ month & date ('D') <$ day )) $ age --;
Return $ age;
}