PHP 闭包函数 function use 用法实例
程序员文章站
2022-05-16 10:38:14
...
/** * @param string $hisStart * @param string $hisEnd * @param int $range * @param string $format * * @return array */function createHisRange($hisStart = '00:00:00', $hisEnd = '23:59:59', $range = 3600, $format = 'H:00:00'){ return array_map(function ($time) use ($format) { return date($format, $time); }, range(strtotime($hisStart), strtotime($hisEnd), $range));}/** * @param $ymdStart * @param bool $ymdEnd * @param int $range * @param string $format * * @return array */function createYmdRange($ymdStart, $ymdEnd = true, $range = 86400, $format = 'Y-m-d'){ return array_map(function ($time) use ($format) { return date($format, $time); }, range(strtotime($ymdStart), strtotime($ymdEnd), $range));}