经测试代码如下:
/**
* 计算年龄
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
function birthday($birthday){
$age = strtotime($birthday);
if($age === false){
return false;
}
list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
$now = strtotime("now");
list($y2,$m2,$d2) = explode("-",$now));
$age = $y2 - $y1;
if((int)($m2.$d2) < (int)($m1.$d1))
$age -= 1;
return $age;
}
echo birthday('1986-07-22');
原文链接:https://www.f2er.com/php/529010.html