PHP常用函数系列--根据生日计算年龄
2023-09-11 14:22:41 时间
/**
* 根据出生年月日计算出年龄
* @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;
}
}
相关文章
- 区别 PHP 的 $_POST、$HTTP_RAW_POST_DATA 和 php://input
- 摄像头拍照,PHP输入流php://input的使用分析
- PHP的$_SERVER['PHP_SELF']造成的XSS漏洞攻击及其解决方案
- PHP中的 变量 与 常量 详解
- PHP-fpm占CPU 100%修复
- PHP基于Redis实现轻量级延迟队列
- PHP动态压缩js,css
- php如何判断是否为json数据(格式)
- php分享二十四:数组
- 开发函数计算的正确姿势———为 PHP 运行时添加自定义扩展
- PHP截取中文字符串不出现?号的解决方法[原创]
- PHP写UltraEdit插件脚本
- [PHP] 如何让 php-fpm 的循环 echo 实时输出到浏览器
- [php-src] Php扩展开发的琐碎注意点、细节
- [php-src] 理解Php内核中的函数与INI
- [转]php 实例说明 socket通信机制
- [转]XCache 3.0.0 发布,PHP 性能提升方案
- php下的原生ajax请求
- PHP计算中文字符串长度 、截取相应中文字符串
- PHP:小数位计算
- 关于php user ini 文件的配置笔记 (TODO)
- php去除换行符的方法小结(PHP_EOL变量的使用)
- xpath php