3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr=array("2018-06-27 20:30:20","2018-06-27 20:31:20","2018-06-27 20:37:20","2018-06-27 20:45:20","2018-06-27 20:48:20"); function roundToNearestMinuteInterval($time, $interval) { $timestamp = strtotime($time); $rounded = round($timestamp / ($interval * 60), 0) * $interval * 60; return $rounded; } $interval = 5; // minutes $start = roundToNearestMinuteInterval(min($arr), $interval); $end = roundToNearestMinuteInterval(max($arr), $interval); for (; $start <= $end; $start += $interval * 60) { $results[] = date('Y-m-d H:i:s', $start); } print_r($results);

preferences:
62.91 ms | 405 KiB | 6 Q