Home  >  Article  >  php教程  >  php根据生日计算年龄的方法,php计算年龄

php根据生日计算年龄的方法,php计算年龄

WBOY
WBOYOriginal
2016-06-13 08:58:041253browse

php根据生日计算年龄的方法,php计算年龄

本文实例讲述了php根据生日计算年龄的方法。分享给大家供大家参考。具体如下:

<&#63;php 
function birthday($birthday){ 
  $age = strtotime($birthday); 
  if($age === false){ 
    return false; 
  } 
  list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age)); 
  $now = strtotime("now"); 
  list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now)); 
  $age = $y2 - $y1; 
  if((int)($m2.$d2) < (int)($m1.$d1)) 
    $age -= 1; 
  return $age; 
} 
echo birthday('1986-07-22'); 
&#63;>

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn