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实现批量修改文件名的方法。分享给大家供大家参考,具体如下: 需求描述: 某个文件夹下有100个文件,现在需要将这个100个文件的文件名后添加字符串Abc(后缀名保持不...

WordPress中登陆后关闭登陆页面及设置用户不可见栏目

WordPress中登陆后关闭登陆页面及设置用户不可见栏目

用户登录后关闭登录页面 WordPress默认的登录页面是:http://WP目录/wp-login.php,登录后会自动跳转到:http://WP目录/wp-admin。现在问题来了,...

php通过asort()给关联数组按照值排序的方法

本文实例讲述了php通过asort()给关联数组按照值排序的方法。分享给大家供大家参考。具体分析如下: php通过asort()给关联数组按照值排序,和sort的区别是,sort为数组中...

PHP simple_html_dom.php+正则 采集文章代码

复制代码 代码如下: <?php //包含PHP Simple html Dom 类库文件 include_once('./simplehtmldom/simple_html_do...

php简单截取字符串代码示例

本文实例讲述了php简单截取字符串的方法。分享给大家供大家参考,具体如下: //截取摘要 public static function mbsubstr($str){ $strl...