参数为多个日期时间的数组,返回离当前时间最近的那个时间

本文阅读 1 分钟
首页 › PHP笔记 › 正文
//我只能想到foreach方式咯,欢迎大神修改
$data = [
    '2020-02-02 11:11:11',
    '2019-02-02 11:55:11',
    '2018-12-02 11:33:11',
    '2017-12-02 11:22:11',
];

$near = array_reduce($data, function($a, $b){
   return abs((time() - strtotime($a))) < abs((time() - strtotime($b))) ? $a : $b;
});

echo $near;
数据库中的事务是什么?
« 上一篇 04-17
http协议的header中有哪些key及含义
下一篇 » 04-17

发表评论