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判断函数是否被定义的方法

本教程将介绍判断函数是否被定义 新建一个246.php,如图所示: 输入php网页的结构(<?php?>),如图所示: 声明PHP与浏览器交互的文件类型和...

继续收藏一些PHP常用函数第1/2页

复制代码 代码如下: <? function GetIP() { //获取IP if ($_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERV...

Php Cookie的一个使用注意点

复制代码 代码如下:<?php setcookie('test', 'this is a cookie test'); echo ($_COOKIE['test']); ?>...

php知道与问问的采集插件代码

最近发现知道和问问小偷的版本越来越多了!! 看过一个百度小偷的网站也达到了pr6。收录十万多!! 在经过 荐礼啦 四十天的实践之后 发现百度对这个确实挺友好的。 从网站访问来看 很多也是...

PHP实现的增强性mhash函数

今天使用php的加密函数mhash 的时候,报错: Fatal error : Call to undefined function mhash() mhash是php的内置函数但是使用...