这篇文章主要介绍了php计算年龄精准到年月日的方法,涉及php操作日期与字符串的相关技巧,非常简单实用,需要的朋友可以参考下
本文实例讲述了php计算年龄精准到年月日的方法。分享给大家供大家参考。具体如下:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class
Age {
/**
* 计算年龄精准到年月日
* @param type $birthday
* @return array
*/
public
function
calAge(
$birthday
) {
list(
$byear
,
$bmonth
,
$bday
) =
explode
(
'-'
,
$birthday
);
list(
$year
,
$month
,
$day
) =
explode
(
'-'
,
date
(
'Y-m-d'
));
$bmonth
=
intval
(
$bmonth
);
$bday
=
intval
(
$bday
);
if
(
$bmonth
< 10) {
$bmonth
=
'0'
.
$bmonth
;
}
if
(
$bday
< 10) {
$bday
=
'0'
.
$bday
;
}
$bi
=
intval
(
$byear
|