3v4l.org

run code in 300+ PHP versions simultaneously
<?php function monthToToday($past, $now, $format = 'Y-m') { $current = strtotime(date('Y-m-1', strtotime($past))); $result = []; while($current < $now) { $result[] = date($format, $current); $current = strtotime('+1 month', $current); } //包含当前月份 $result[] = date($format, $current); return $result; } print_r(monthToToday('2013-12-25', time()));

preferences:
45.4 ms | 402 KiB | 5 Q