欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

PHP輸入年月日期實現(xiàn)計算年齡功能

這篇文章給大家分享的是PHP輸入年月日期實現(xiàn)計算年齡功能,相信大部分人都還沒學會這個技能,為了讓大家學會,給大家總結(jié)了以下內(nèi)容,話不多說,一起往下看吧。

創(chuàng)新互聯(lián)建站專注于綠園網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供綠園營銷型網(wǎng)站建設,綠園網(wǎng)站制作、綠園網(wǎng)頁設計、綠園網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務,打造綠園網(wǎng)絡公司原創(chuàng)品牌,更為您提供綠園網(wǎng)站排名全網(wǎng)營銷落地服務。

PHP輸入年月日期實現(xiàn)計算年齡功能

廢話不多說,之間上代碼:

<?php
/**
 * 根據(jù)出生年月日計算出年齡
 * @param $birth_year 
 * @param $birth_month
 * @param $birth_day
 * @return int
 */
function getAgeByBirth($birth_year,$birth_month,$birth_day){
  if(empty($birth_year) || empty($birth_month) || empty($birth_day)){
    return 0;
  }
  $current_year = date('Y',time());
  $current_month = date('m',time());
  $current_day = date('d',time());
  if($birth_year >= $current_year){
    return 0;
  }
  $age = $current_year - $birth_year - 1;
  if($current_month>$birth_month){
    return $age+1;
  }else if($current_month == $birth_month && $current_day>=$birth_day){
    return $age+1;
  }else{
    return $age;
  }
}
//測試:
echo getAgeByBirth('1988','4','8');
?>

運行結(jié)果:

32

以上就是PHP輸入年月日期實現(xiàn)計算年齡功能的具體操作,代碼詳細清楚,如果在日常工作遇到這個問題,希望你能通過這篇文章解決問題。如果想了解更多相關內(nèi)容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章題目:PHP輸入年月日期實現(xiàn)計算年齡功能
文章分享:http://www.chinadenli.net/article18/piisdp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作建站公司域名注冊Google靜態(tài)網(wǎng)站自適應網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設