PHP 年龄计算函数(精确到天)

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
/**
* PHP 年龄计算函数
*
* 参数支持数组传参和标准的 Mysql date 类型传参
* params sample
* --------------------------------------------------
$birthArr = array(
'year' => '2000',
'month' => '11',
'day' => '3'
);
$birthStr = '2000-11-03';
* --------------------------------------------------
* );
* @author IT不倒翁 <itbudaoweng@gmail.com>
* @copyright (c) 2011,2012 Just Use It!
* @link IT不倒翁 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 '2000-11-03 12:12:00'
}
}
$age = date('Y') - $year;
if (date('m') < $month || (date('m') == $month && date('d') < $day)) $age--;
return $age;
}

相关文章

PHP发送邮件确认验证注册功能示例【修改别人邮件类】

PHP发送邮件确认验证注册功能示例【修改别人邮件类】

本文实例讲述了PHP发送邮件确认验证注册功能。分享给大家供大家参考,具体如下: 类库: require "class.phpmailer.php"; require "class....

php intval的测试代码发现问题

<?php $o = 0.1; for($a = 1; $a < 100; $a++){ &n...

php $_SERVER当前完整url的写法

复制代码 代码如下:"http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];...

PHP超级全局变量数组小结

php超级全局变量列表 $_GET[] 获得以GET方法提交的变量数组 $_POST[] 获得以POST方法提交的变量数组 $_COOKIE[] 获取和设置当前网站的Cookie标识 $...

PHP实现通过strace定位故障原因的方法

本文实例讲述了PHP实现通过strace定位故障原因的方法。分享给大家供大家参考,具体如下: 俗话说:不怕贼偷,就怕贼惦记着。在面对故障的时候,我也有类似的感觉:不怕出故障,就怕你不知道...