亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2012年06月07日 16:45:11   作者:  
因為一個具體的項目中要用到年齡計算,根據(jù)生日計算出當前的年齡。這個精確到天,和騰訊是一樣的,大家有需要的可以參考一下
復制代碼 代碼如下:

<?php
/**
* PHP 年齡計算函數(shù)
*
* 參數(shù)支持數(shù)組傳參和標準的 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;
}

相關文章

最新評論