欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP 年齡計(jì)算函數(shù)(精確到天)

 更新時(shí)間:2012年06月07日 16:45:11   作者:  
因?yàn)橐粋€(gè)具體的項(xiàng)目中要用到年齡計(jì)算,根據(jù)生日計(jì)算出當(dāng)前的年齡。這個(gè)精確到天,和騰訊是一樣的,大家有需要的可以參考一下
復(fù)制代碼 代碼如下:

<?php
/**
* PHP 年齡計(jì)算函數(shù)
*
* 參數(shù)支持?jǐn)?shù)組傳參和標(biāo)準(zhǔn)的 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;
}

相關(guān)文章

最新評(píng)論