php日常摘要
来源:互联网 发布:sdwebimage原理lru算法 编辑:程序博客网 时间:2024/06/06 08:56
本文记录工作用日常用到的PHP方法,方便日后使用。
1,从数组中随机取N个元素
/** * 从数组中随机取N个元素 * @param $array 原数组 * @param $number int 随机元素个数 * @return array 新数组 */protected static function the_array_rand($array,$number = 21){ if(count($array) <= $number) return $array; shuffle($array); return array_slice($array,0,$number-1);}2,获取给定时间距现在时间,用于格式化显示时间
/** * 获取时间距当前的时间 * @param $time 指定时间戳 * @return false|string */ public static function getTimeDifference($time) { $time = (int) substr($time, 0, 10); $int = time() - $time; if ($int <= 5){ $str = '刚刚'; }elseif ($int < 60){ $str = $int.'秒前'; }elseif ($int < 3600){ $str = floor($int / 60).'分钟前'; }elseif ($int < 86400){ $str = floor($int / 3600).'小时前'; }elseif ($int < 2592000){ $str = floor($int / 86400).'天前'; }else{ $str = '一个月前'; } return $str; }
阅读全文
0 0
- php日常摘要
- PHP函数摘要
- php截取文章摘要
- PHP语法摘要
- PHP WEB安全摘要
- php摘要认证
- PHP学习摘要
- PHP代码段摘要
- php 日常开发积累
- php 日常函数
- PHP日常吐槽
- PHP日常试题1.1
- php小事日常记
- php日常问题汇总
- 《SVN使用教程》笔记摘要,及日常问题和解决办法
- PHP SPL 数据结构笔记摘要
- PHP日常实用小Tips
- PHP日常开发小技巧
- XYNUOJ 1118: 习题8-4 移动数据
- Java数组--Arrays类
- andorid 集成开发环境下载
- 括号匹配
- QT开发——在QT Creator加入lib库文件
- php日常摘要
- 虚函数表解析
- IOS ARKit 最新文档
- Windwos 10 Install VMware PowerCLI 6.5.0
- 使用线性神经网络实现逻辑与和逻辑异或(一)
- JavaScript 类型转换
- 【面经笔记】字节对齐
- 软工文档小结
- Spring源码-目录