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 /* *文件上传类 **/ class upfile{ private $fi...

php获取数组中重复数据的两种方法

(1)利用php提供的函数,array_unique和array_diff_assoc来实现 复制代码 代码如下: <?php function FetchRepeatMember...

php数据库密码的找回的步骤

1.用系统管理员登陆系统。 2.停止MySQL的服务。 3.进入命令窗口,然后进入MySQL的安装目录,比如我的安装目录是c:mysql,进入C:mysqlbin 4.跳过权限检查启动M...

PHP常用函数小技巧

1. 返回文件扩展名 function getformat($file) { $ext=strrchr($file,"."); $format=strtolower($ext); ret...

将PHP从5.3.28升级到5.3.29时Nginx出现502错误

今天将PHP从5.3.28升级到5.3.29,发现网站打不开了,提示”502 bad gateway”,访问静态资源可以,但访问任何PHP文件都会502。 其实之前也发现这个问题,只是一...