来源:未知 时间:2015-07-13 17:44 作者:xxadmin 阅读:次
[导读] 实例讲述了php根据生日计算年龄的方法。 ?phpfunctionbirthday($birthday){$age=strtotime($birthday);if($age===false){returnfalse;}list($y1,$m1,$d1)=explode(-,date(Y-m-d,$age));$now=strtotime(now);list($y2,$m2,$d2)=explode(-,dat...
|
实例讲述了php根据生日计算年龄的方法。 <?php
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("-",date("Y-m-d",$now));
$age = $y2 - $y1;
if((int)($m2.$d2) < (int)($m1.$d1))
$age -= 1;
return $age;
}
echo birthday('1986-07-22');
?> |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com